vue中nextTick的用途!

nextTick的用途!

官网说法:

在下次 DOM 更新循环结束之后执行延迟回调。在修改数据之后立即使用这个方法,获取更新后的 DOM

个人理解:需要在视图更新之后,基于新的视图进行操作。

<div id="app">
  <input ref="input" v-show="inputShow">
  <button @click="show">show</button>  
 </div>

export default { 
 data() {
   return {
     inputShow: false
   }
  },
  methods: {
    show() {
      this.inputShow = true
      this.$nextTick(() => {
        this.$refs.input.focus()
      })
    }
  }
}

北漂生活不易,觉得对你有帮助,打赏一下小编吧!
这里写图片描述

猜你喜欢

转载自blog.csdn.net/qq_37339364/article/details/82181907