【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);
注:以上内容仅用于日常学习