15、Vue3 nextTick函数

作者: 圆梦人生 | 来源:发表于2022-07-12 08:49 被阅读0次
  • 作用:
    • 当你在 Vue 中更改响应式状态时,最终的 DOM 更新并不是同步生效的,而是由 Vue 将它们缓存到“next tick”以确保每个组件无论发生多少状态改变,都仅执行一次更新

案例

<template>
  <div>{{val1}}</div>
</template>

<script>
import { ref } from '@vue/reactivity'
import { nextTick } from '@vue/runtime-core';
export default {
    setup(){
        let val1 = ref(200);
        //
        nextTick(()=>{
            console.log('nextTick ====');
        })
        //
        return {
            val1
        }
    }
}
</script>

相关文章

网友评论

    本文标题:15、Vue3 nextTick函数

    本文链接:https://www.haomeiwen.com/subject/ibqibrtx.html