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

Vue.nextTick(() => {})  /  this.$nextTick(() => {// 更新完成})

<template lang="html">
   <div>
       <span>{{msg}}</span>
   </div>
</template>

<script>
export default {
    data () {
        return {
            msg: '没有更新之前'
        }
    },
    methods: {
        updateMsg () {
            this.msg = '更新完成'
            console.log('aaa', this.$el.textContent) // 没有更新之前
            this.$nextTick(() => {
                console.log('bb', this.$el.textContent) // 更新完成
            })
        }
    },
    mounted () {
        this.updateMsg()
    }
}
</script>

<style lang="css">
</style>

 

相关文章:

  • 2021-12-02
  • 2021-09-29
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-07
  • 2021-07-30
  • 2022-12-23
  • 2021-06-06
  • 2021-06-25
相关资源
相似解决方案