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