首页 > 编程语言 > 详细

watch监听数组

时间:2020-02-10 16:35:14      阅读:171      评论:0      收藏:0      [点我收藏+]
watch: {
    totalCount (newValue, oldValue) {
          this.totalCount1 = newValue
      },
    loading (newValue, oldValue) {
            this.loading1 = newValue
        },
   sceneClassList: { // 注意监听的时候不要漏掉空数据的情况
     handler(newValue, oldValue) {
         console.log(‘newValue‘, newValue)
        if (newValue.length) { //监听有数据的情况
          for (let i = 0; i < newValue.length; i++) {  
                if (oldValue[i] != newValue[i]) {
                  console.log(‘this.sceneClassList‘, this.sceneClassList)
                  this.sceneClassList1 =  this.sceneClassList
                  this.$nextTick(function() {
                    this.heightOfDl = this.$refs.dlHeight.offsetHeight + ‘px‘
                    this.$emit(‘updateHeightOfDl‘, this.heightOfDl)
                  })
                  
                } 
              }
        } else { // 监听空数据的情况
          this.sceneClassList1 = []
              this.$nextTick(function() {
                this.heightOfDl = this.$refs.dlHeight.offsetHeight + ‘px‘
                this.$emit(‘updateHeightOfDl‘, this.heightOfDl)
              })


        }
    },
    deep: true

    }
}                    

 

watch监听数组

原文:https://www.cnblogs.com/mmzuo-798/p/12291264.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!