【Vue-bug】-Error in nextTick: "TypeError: Cannot read property '$el' of undefined"


加上if判斷,先判斷是否存在,否則不執行

 this.getTitleTopY = debounce(() => {
      if (this.$refs.param && this.$refs.comment && this.$refs.goodsList) {
        this.$nextTick(() => {
          //獲取不同組件的offsetTop
          this.titleTopY = [];
          this.titleTopY.push(0);
          this.titleTopY.push(this.$refs.param.$el.offsetTop - 44);
          this.titleTopY.push(this.$refs.comment.$el.offsetTop - 44);
          this.titleTopY.push(this.$refs.goodsList.$el.offsetTop - 44);
          this.titleTopY.push(Number.MAX_VALUE);
          console.log("我");
        });
      }
    }, 500);


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM