VUE 动态修改data 中数据或添加属性值
vue 中data 数据更新后页面不同步动态渲染更新
![vue官方文档说明](https://img-blog.csdnimg.cn/08b05a5766a24ad591856dad973b01c3.png)
- 为对象添加属性或修改指定属性
var student= {
name: '李明'
};
this.$set(student, 'name', '陈明');
this.$set(student, 'sex', '男');
console.log(student);
- 为数组添加属性或修改数组值
var arr = [1, 2, 3];
this.$set(arr, 3, 4);
console.log(arr);
this.$set(arr, 0, 4);
console.log(arr);
- 修改数组对象属性值(vue 2)
data(){
materialList:[
{
materialId: "19580",
deptMatterId: "350",
applicationMaterialId: "7505",
name: "身份证",
checkMain: "",
type: "办理材料",
delFlag: "0",
old: true,
examples: [],
styles: [],
fileList: []
},
],
}
this.$set(
this.materialList,strIndex,
{...this.materialList[strIndex],
fileList:[{name:'文件名',url:'http://123456.com'}]
}
)
materialList:[
{
materialId: "19580",
deptMatterId: "350",
applicationMaterialId: "7505",
name: "身份证",
checkMain: "",
type: "办理材料",
delFlag: "0",
old: true,
examples: [],
styles: [],
fileList: [
{name:'文件名',url:'http://123456.com'}
]
},
],