props傳值遇Cannot read property getAttribute of undefined異常

今有一個echarts 圖標的子組件使用watch 監聽接受父組件傳入的data,而在父組件頁面再次根據日期篩選數據,重新傳入子組件進行圖表重繪時老實會提示報錯

在這裏插入圖片描述


vue.runtime.esm.js?6e6d:619 [Vue warn]: Error in callback for watcher "chartData": "TypeError: Cannot read property 'getAttribute' of undefined"

found in

原來是異步加載數據切換的鍋,watch 中是一個異步函數,再監聽到值變化後,真正的值其實並未返回

  watch: {
    chartData(val) {
      if (val) {
        this.chartParentShow = true
        this.$nextTick(() => {
          this.drawLine(val)
        })
      } else {
        this.chartParentShow = false
      }
    }
  },
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章