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