【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);
posted @ 2020-08-02 22:56  Wayhome'  阅读(13150)  评论(0编辑  收藏  举报
// 侧边栏目录 // https://blog-static.cnblogs.com/files/douzujun/marvin.nav.my1502.css