What is Vue nextTick? Accessing the DOM after Data Updates

Vue's nextTick is a core function that helps manage the timing of DOM updates in Vue applications. It provides a way to execute code after Vue has finished updating the DOM, ensuring you're working with the latest rendered state.
How Vue Updates Work
Vue performs DOM updates asynchronously. When you change reactive data, Vue doesn't immediately update the DOM. Instead, it:
- Batches multiple data changes into a single update
- Places these updates in an async queue
- Processes the queue on the next "tick" of the event loop
This optimization prevents unnecessary DOM updates and improves performance.
When to Use Vue nextTick
You need nextTick when:
- Accessing updated DOM elements immediately after changing data
- Performing operations that depend on the new DOM state
- Measuring updated element dimensions (for example
clientWidthandclientHeight) - Working with third-party libraries that manipulate the DOM (such as charts.js).
Practical Example of Vue nextTick for Auto Scrolling a List to the Bottom after Data Change
Let’s take a look at a practical example of when nextTick might be helpful. In the code below, we're adding items to a scrollable list. Without nextTick, attempting to scroll to the bottom immediately after adding an item wouldn't work but using nextTick ensures we access the correct scrollHeight after the DOM has been updated.
<script setup>
import { ref, nextTick } from 'vue';
const items = ref([]);
const newItem = ref('');
const itemsList = ref(null);
const addItem = async () => {
// Add item to list
items.value.push(newItem.value);
newItem.value = '';
// This won't work immediately
console.log('before DOM Update', itemsList.value.scrollHeight);
// Wait for DOM update
await nextTick();
// Now we can safely access the updated DOM
const container = itemsList.value;
container.scrollTop = container.scrollHeight;
console.log('after DOM Update', itemsList.value.scrollHeight);
};
</script>
<template>
<div>
<div ref="itemsList" class="items-container">
<div v-for="item in items" :key="item">
{{ item }}
</div>
</div>
<input v-model="newItem" @keyup.enter="addItem" />
<button @click="addItem">Add Item</button>
</div>
</template>
<style scoped>
.items-container {
height: 50px;
margin-bottom: 5px;
border: 1px solid black;
padding: 5px;
overflow: scroll;
}
</style>See the example in action in this StackBlitz playground. Try removing the nextTick to see what happens.
How to use Vue’s nextTick with the Composition API
nextTick must be imported from Vue and can be used in a couple different ways. Since it returns a promise you can await the promise resolution. You can use .then to call a function when the promise resolves. Finally, you could pass it a callback function as the only argument.
// Using nextTick imported from vue
import { nextTick } from 'vue'
// Promise syntax
await nextTick()
// DOM is now updated
// Alt promise syntax
nextTick().then(()=>{
// DOM is now updated
})
// Callback syntax
nextTick(() => {
// DOM is now updated
})Common Gotchas When Using nextTick
While extremely handy, there are a couple common mistakes people make when using nextTick just like some other tools Vue provides.
- Don't overuse nextTick - only use it when you actually need to access the updated DOM
nextTickdoesn't guarantee third-party DOM changes are complete, only Vue's updates, so consult the thrid-party’s docs for info on any events they provide
Conclusion
While not a tool you reach for every day, understanding nextTick can help elevate your Vue development skills and open up more possibilities for good UX.
Start learning Vue.js for free

Comments
Latest Vue School Articles
5 Component Design Patterns to Boost Your Vue.js Applications

Vibe Coding a Collaborative Editor with Comment Support with Nuxt UI and Jazz

Our goal is to be the number one source of Vue.js knowledge for all skill levels. We offer the knowledge of our industry leaders through awesome video courses for a ridiculously low price.
More than 200.000 users have already joined us. You are welcome too!
© All rights reserved. Made with ❤️ by BitterBrains, Inc.


