<template>
<div>
<div ref="sb">{{message}}</div>
<button @click="change">change</button>
</div>
</template>
<script setup lang="ts">
import {ref,nextTick} from 'vue'
const message =ref('sblc')
const sb = ref(null)
const change=()=>{
message.value='sb'
nextTick(()=>{
console.log(sb.value.innerText)
})
//setTimeout(()=>{console.log(sb.value.innerText)},0)
}
</script>
vue 数据变化需要更新dom时是异步更新。vue 在内部对异步队列尝试使用promise.then,MutationObserve,setImmediate,如果执行环境不执行,在采用setTimeOut(fn,0)