繁体   English   中英

如何从data()vue.js的两个不同的地方显示v-for

[英]how to show v-for from two different aray from data() vue.js

<ul class="chart-box__info-chartlist">
   <li v-for="item in datachart.labels">
       <i class="chart-icon chart-icon_1"></i>
       <span>{{ item.label }} - {{ item.color }}</span> 
   </li>
</ul>  

data() {
            return {
                cb_info_sm: this.links[0].cb_info_sm,
                cb_info_sm_color: this.links[0].cb_info_sm_color,
                cb_info_label: this.links[0].cb_info_label,
                cb_info_url: this.links[0].cb_info_url,
                activeclass: 0,
                datachart: {
                    labels: this.links[0].data_lables.map( item => item.title),
                    datasets: [{
                        label: 'Chart',
                        backgroundColor: this.links[0].data_lables.map( item => item.color),
                        data: this.links[0].data_lables.map( item => item.value),
                        borderColor: '#ffffff'
                    }]
                }
            }
        },

数据在变化,我需要从datachart.datasets [0] .backgroundColor和datachart.labels显示两个值,也许有人知道,如何用v-for做到这一点?

您的代码很脏,我建议您重组和清理您的数据图表对象,但是如果您坚持要保留此对象,则可以定义一个计算属性并对此进行v-for:

computed : {
  newDataChart () {
    return this.datachart.labels.map(item => {label: item, color: this.datachart.datasets[0].backgroundColor})
  }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM