vue项目 不能检测数组或对象改变问题

通过数组对象的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])   

   }     

    },

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。