vue中mounted中無法獲取到dom元素


一、解決方案:

加上異步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)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM