vue报错Cannot read property 'addEventListener' of null"

VUE监听内部元素滚动时报错Cannot read property 'addEventListener' of null",代码如下:
mounted () {
this.$nextTick(function () {
let targetScroll = document.getElementById("dialogScroll")
targetScroll.addEventListener('scroll', this.handleScroll)
});
},
methods: {
handleScroll (){
this.scrollTop = document.getElementById("dialogScroll").scrollTop
console.log(this.scrollTop)
},
},

你是不是在另一个组件中引入你这些代码所在的组件 所以会导致这个错误

光看js代码,是没有错误的,报这个错误的原因是获取id元素的时候没有获取到,你可以看一下你页面中的这个id元素是不是在dom加载完成之后动态添加上去的。