在数组的对象里面,自己手动添加的属性是不具备响应式的

时间:2019-08-10 18:42:26   收藏:0   阅读:87

在数组的对象里面,自己手动添加的属性是不具备响应式的,所以在添加的时候要用$set,如

         this.noticeList = requestParams.page === 1 ? rlist : this.noticeList.concat(rlist)
          this.noticeList.forEach((item) => {
            this.$set(item, 'isCheck', false)
          })
          

如果你没有用set ,而是直接 item.isCheck = false这样
到后面你更改数据的时候要用forceUpdate

     this.$set(this.noticeList[index], 'isCheck', !this.noticeList[index].isCheck)
      this.$forceUpdate('noticeList', this.noticeList)

所以记住要用set哦

原文:https://www.cnblogs.com/antyhouse/p/11332245.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!