watch监听数组

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

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