总结:
1.数组更改值,不会触发更新;增长删除值可触发更新。
2.对象更改值可触发更新,增长或者删除属性不会触发更新。
3.对象数组:数组中的对象更改值会触发更新。数组
1、纯数组-------showArr:[true,true]this
数组中元素直接赋值,---不触发刷新code
this.showArr[0]=!this.showArr[0];
数组修改后总体赋值,---不触发刷新对象
var parr=this.showArr; parr[0]=!parr[0]; this.showArr=parr;
数组从新复制出一份新的,修改后总体赋值,---可触发刷新总结
var parr=this.showArr.slice(0); parr[0]=!parr[0]; this.showArr=parr;
用$set赋值,---可触发刷新co
this.$set(this.showArr,0,!this.showArr[0])
2、纯对象-------showArr:{'showBool':true}let
对象中元素直接赋值,---可触发刷新push
this.showArr['showBool']=!this.showArr['showBool'];
对象修改后总体赋值,---可触发刷新delete
var parr=this.showArr; parr['showBool']=!parr['showBool']; this.showArr=parr;
用$set赋值,---可触发刷新
this.$set(this.showArr,'showBool',!this.showArr['showBool']);
3、 对象数组-------showArr:[{'showBool':true},{'showBool':true}]
数组中元素直接赋值,---可触发刷新
this.showArr[0]['showBool']=!this.showArr[0]['showBool'];
数组修改后总体赋值,---可触发刷新
var parr=this.showArr; parr[0]['showBool']=!parr[0]['showBool']; this.showArr=parr;
数组从新复制出一份新的,修改后总体赋值,---可触发刷新
var parr=this.showArr.slice(0); parr[0]['showBool']=!parr[0]['showBool']; this.showArr=parr;
用$set赋值,---可触发刷新
this.$set(this.showArr[0],'showBool',!this.showArr[0]['showBool']);
4、数组或对象增长删除值:
this.numArr.push(4);//---(数组增长元素)可触发刷新 this.numArr.splice(1,1);//---(数组删除元素)可触发刷新 this.numObj.m=4;//---(对象增长属性)不触发刷新 delete this.numObj.y;//---(对象删除属性)不触发刷新