數(shù)據(jù)格式定義:
list:{
1:[],
2:[],
3:[]
}
- 原因:若在上述的數(shù)據(jù)格式的情況下,采用如下方式,進(jìn)行賦值,vue是不會(huì)進(jìn)行渲染的
list[index] = data;
- 解決方法:采用官方的 this.$set
// list 為對(duì)應(yīng)對(duì)象 {[1,2,4],[3,5]}
// index 為 list 對(duì)應(yīng)下標(biāo)
// data 為將要賦值的數(shù)據(jù)
this.$set(list,index,data);
- 原因:對(duì)象多層嵌套
- 解決方法:對(duì)最頂層數(shù)據(jù)重新賦值
// 利用 JSON.parse
let data = JSON.parse(JSON.stringify(this.form.serviceMoneyId));
this.form.serviceMoneyIdObj = {};
this.form.serviceMoneyIdObj = JSON.parse(JSON.stringify(data));
// 利用解構(gòu)
let data = [
...data,
[name]:{
id:id,
code:code
}
]