“TypeError: that.$refs.videoItem.getBoundingClientRect is not a function“
程序员文章站
2024-01-31 08:39:25
...
获取节点距顶部高度时使用 getBoundingClientRect() 方法报错:
vue.runtime.esm.js?2b0e:619 [Vue warn]: Error in nextTick: “TypeError: that.$refs.videoItem.getBoundingClientRect is not a function”
搜到的都是在说需要在销毁阶段要取消监听scroll,我这个并不是,仔细看了下导致找不到的原因发现是我给的组件ref导致的。组件 .$refs 拿到的是VueComponent,加个 .$el 就能拿到了
<vVideoItem ref="videoItem"></vVideoItem>
<div ref="aa"></div>
mounted() {
this.$nextTick(()=>{
let itemH= this.$refs.videoItem.$el.getBoundingClientRect().top;
console.log(itemH);
window.addEventListener('scroll', this.handleScroll);
// let aa= this.$refs.aa.getBoundingClientRect().top;
// console.log(aa);
})
},
beforeDestroy() {
window.removeEventListener('scroll', this.handleScroll)
},
上一篇: 读大文件查找符合的电话号码
下一篇: 独家揭秘!吉祥阁风水灵宝怎么样?
推荐阅读
-
TypeError: that.setData is not a function/使用了var that=this仍报错
-
“TypeError: that.$refs.videoItem.getBoundingClientRect is not a function“
-
Error in v-on handler: “TypeError: _this3.addForm.goods_cat.join is not a function
-
TypeError: _this.setStore is not a function at eval
-
Error in created hook: “TypeError: Object(...) is not a function“
-
TypeError: 'function' object is not subscriptable
-
d3.svg.line()错误:TypeError: d3.svg.line is not a function
-
Vue 报错TypeError: this.$set is not a function 的解决方法
-
UnhandledPromiseRejectionWarning: TypeError: loaderContext.getResolve is not a function
-
关于Uncaught TypeError: validator.resetForm is not a function错误的问题