watch:{
"list"(){
console.log("觸發數組變化")
},
}
methods中:
change(){
for(let i=0;i<this.list.length;i++){
this.list[i] = "11111";
this.$set(this.list, this.list[i], "11111")
}
console.log(this.list);
},
for循環內部是不知語句,第二句是觸發數組更新的語句。
<button @click="change">測試</button>
關於這個問題,我嘗試了網上一些其他的辦法 例如deep:true handler的方法,都不能達到我要的條件,以上方法親測有效,但是 this.$set(this.someObject,key,value)中,後兩個賦值語句沒有生效,但是出發了更新