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

    }
}                    

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM