【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