使用场景:当你在修改值之后想要获取最新的dom时
<template>
<div>
<div>
<div ref="textDom">{{ text }}</div>
<button @click="btn">改变</button>
</div>
</div>
</template>
<script setup lang="ts">
const text = ref('梁延涛')
const textDom = ref()
// nextTick 函数需要配合 async await 来使用
const btn = async () => {
text.value = '李子天'
await nextTick()
console.log(textDom.value?.innerText); // 李子天
}
</script>
<style scoped lang="less">
</style>