1<template>
2 <button id="counter" @click="increment">{{ count }}</button>
3</template>
4
5<script lang="ts" setup>
6import { ref, nextTick } from 'vue'
7const count = ref(0)
8
9async function increment() {
10 count.value++
11
12 // DOM 还未更新
13 console.log(document.getElementById('counter').textContent) // 0
14
15 nextTick(() => {
16 // DOM 此时已经更新
17 console.log(document.getElementById('counter').textContent) // 1
18 })
19}
20</script>