html:
<div id="test">
<input type="button" @click="fn1()">{{arr['x']}}
<input type="button" @click="fn2()">{{arr['y']}}
</div>
js:
data: {
arr: ['x', 'y'],
z: 5
},
fn2() {
Vue.set(this.arr, 'y', ++this.arr['y']);
// ++this.z;
console.log(this.arr);
}
// 一旦有++this.z这句 就能成功更新渲染,一旦注释这句则无法渲染到dom上,但arr仍然成功更新,求解
你得把arr改成对象而不是一个数组