一、解决方案:
加上异步setTimeout,延迟获取dom的代码的执行
mounted() { // debugger this.$nextTick(()=> { setTimeout(()=> { let el = document.querySelector('.table') console.log(el) if(el) { // debugger this.offsetTop = el.offsetTop window.onscroll = () => this.getInvitationRecordUserList(this) } }) }) },
任务:
1、搞清楚vue中dom的渲染过程
2、vue技术揭秘:深入响应式原理代码分析(https://ustbhuangyi.github.io/vue-analysis/reactive/reactive-object.html#initstate)