一、解決方案:
加上異步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)