watch:{
'data'(oval,nlva){
this.title = this.data.area3.title
this.Item = this.data.area3
Object.keys(this.Item).forEach((key,index) => {
// key 是对象的属性名,this.Item[key] 是对应的属性值,index是对应下标
console.log(key, this.Item[key],index);
if(key != 'title'){
this.Item[key].color = this.color[index-1]
}
});
}
},
onLoad(query) {},
created(){
},
computed:{
},
data(){
return{
title:'',
Item:{},
color: ['#387EFF', '#FFC800', '#B3A0FF', '#2BD9C5', '#54C6FF'],
}
对象,不能直接使用forEach,所以需要先通过Object。keys进行转换
以上是为Item添加color属性操作步骤