DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
World desk2 min

Vue `nextTick`: Wait for the DOM to Update Before Accessing It

Vue batches reactive DOM updates. In Vue 3, await nextTick() after the relevant state change before accessing the updated DOM.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

In Vue 3, update reactive state first, then await nextTick() before reading or acting on the DOM that depends on that change. Vue batches DOM updates, so the rendered page may still show the previous state immediately after a mutation.

Why Vue’s DOM can still show the old value

When reactive state changes, Vue buffers the resulting component updates and applies them in the next update flush rather than synchronously after each mutation. This batching lets Vue combine changes and avoid rendering repeatedly for every individual assignment. As a result, code that reads an element immediately after changing a ref or component property may observe the DOM from before that change.

As an Amazon Associate I earn from qualifying purchases.

Vue describes nextTick() as a utility for waiting for the next DOM update flush. Awaiting it after the relevant mutation lets dependent code run after Vue has applied that update. Vue 3 Global API: General

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use nextTick() after the state change

Composition API in Vue 3

Import nextTick as a named export from vue. In an asynchronous function, await it immediately after the mutation whose DOM result you need:

import { ref, nextTick } from 'vue'

const message = ref('before')

async function updateMessage() {
  message.value = 'after'
  await nextTick()

  // Vue has applied the DOM update for this change.
  // Read or act on the updated element here.
}

The Promise resolves when Vue’s next DOM update flush has completed. You can also pass a callback to nextTick(); awaiting the Promise is often simpler when the surrounding function is already async. Vue 3 Global API: General

Options API in Vue 3

The same named import works in an Options API component. Call it after assigning the component property:

import { nextTick } from 'vue'

export default {
  data() {
    return { message: 'before' }
  },
  methods: {
    async updateMessage() {
      this.message = 'after'
      await nextTick()

      // The DOM now reflects this update.
    }
  }
}

Options API components also provide this.$nextTick(). When you use its callback form, the callback’s this is bound to the component instance. Vue 3 Global API: General

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose nextTick() or the updated hook

Option When it runs Best fit
nextTick() After the next Vue DOM update flush following the point where it is called. DOM work tied to one specific state change.
updated lifecycle hook After component DOM updates generally. Work that belongs after component updates broadly, rather than after one specific mutation.

Vue’s lifecycle guidance recommends nextTick() when you need the updated DOM after a particular state change. Avoid changing component state inside updated: Vue warns that doing so can trigger an infinite update loop. Vue 3 Options: Lifecycle

Vue 2 and Vue 3 use different global syntax

For current Vue 3 code, import the named function with import { nextTick } from 'vue'. Vue 2 examples commonly use Vue.nextTick(callback) or this.$nextTick(callback), and its API documentation advises calling it immediately after changing data when waiting for the DOM update. Treat those global examples as Vue 2 syntax, not as the Vue 3 import pattern. Vue 3 Global API: General · Vue 2 API

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

What nextTick() does not wait for

nextTick() waits for Vue’s DOM update flush; it is not a promise that every part of the browser’s rendering or other asynchronous work is finished. The Vue API documentation does not establish that it waits for images to load, CSS transitions to complete, a browser frame to paint, or unrelated asynchronous operations. If your code depends on one of those events, wait for that event separately. Vue 3 Global API: General

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.