通过数组对象的index改变数组对象,console.log可以打印数据已更新,可是view层检测不到
vue2.0:
由于 JavaScript 的限制,Vue 不能检测以下变动的数组:
当你利用索引直接设置一个项时,例如:vm.items[indexOfItem] = newValue
当你修改数组的长度时,例如:vm.items.length = newLength;
有两种方法可以解决:
1、this.$set的方法
2、js的splice方法 通过替换数组来达到改变view层内容改变
select(index) {
if(this.commentTags[index].p_show==false{
this.commentTags[index].p_show=true;
this.commentTags.splice(index,1,this.commentTags[index])
}else{
this.commentTags[index].p_show=false;
this.commentTags.splice(index,1,this.commentTags[index])
}
},