javascript / intermediate
Snippet
Coordinating with nextTick
Vue updates the DOM asynchronously after state changes. The nextTick function returns a promise that resolves after the current DOM update cycle is complete, allowing you to safely perform calculations on updated elements.
snippet.js
javascript
1
2
3
4
5
async function updateAndMeasure() {count.value++;await nextTick();console.log(content.value.offsetHeight);}
vue
Breakdown
1
await nextTick()
Pauses the function execution until the DOM has been fully rendered with the new state values.