1-1 $nextTick

  1. 1-1 $nextTick底层源码是使用定时器+Promise实现的
  2. 1-2 $nextTick里面的代码会在DOM更新后执行
  3. 1-3 $nextTick会在所有的子组件加载完毕之后再执行
  1. <div id="app">
  2. <div ref="test">test</div>
  3. </div>
  4. <script>
  5. new Vue({
  6. el:"#app",
  7. created() {
  8. console.log(this.$refs)
  9. this.$nextTick(()=>{
  10. console.log(this.$refs)
  11. })
  12. },
  13. mounted() {
  14. console.log(this.$refs)
  15. },
  16. })
  17. </script>