Vue.JS 在数组里的对象中添加新的属性
代码】Vue,JS 在数组里的对象中添加新的属性。
·
data() {
return {
group: [ // 对象数组
{
id: '1',
name: '任务1',
disable: false,
},
{
id: '2',
name: '任务2',
disable: false,
},
{
id: '3',
name: '任务3',
disable: false,
}
]
}
},
created() {
console.log("created已经执行了"); // 工作中,往往在这个created方法中使用ajax请求获取服务端的数据,并加载到data属性中。
for (let i = 0; i < this.group.length; i++) {
this.group[i].num= 0 // 在数组里的对象中添加新的属性"num"
}
},
更多推荐
已为社区贡献1条内容
所有评论(0)