Skip to content

Lifecycle Hooks

Here's the provided information converted into a markdown table format:

App Hooks (runtime)

HookArgumentsEnvironmentDescription
app:createdvueAppServer & ClientCalled when initial vueApp instance is created.
app:errorerrServer & ClientCalled when a fatal error occurs.
app:error:clearedServer & ClientCalled when a fatal error is cleared.
app:data:refreshkeys?Server & Client(internal)
vue:setup-Server & Client(internal)
vue:errorerr, target, infoServer & ClientCalled when a Vue error propagates to the root component.
app:renderedrenderContextServerCalled when SSR rendering is done.
app:redirected-ServerCalled before SSR redirection.
app:beforeMountvueAppClientCalled before mounting the app, only on client side.
app:mountedvueAppClientCalled when Vue app is initialized and mounted in browser.
app:suspense:resolveappComponentClientOn Suspense resolved event.
app:manifest:updateClientCalled when there is a newer version of your app detected.
link:prefetchtoClientCalled when a <NuxtLink> is observed to be prefetched.
page:startpageComponent?ClientCalled on Suspense pending event.
page:finishpageComponent?ClientCalled on Suspense resolved event.
page:loading:start-ClientCalled when the setup() of the new page is running.
page:loading:end-ClientCalled after page:finish.
page:transition:finishpageComponent?ClientAfter page transition onAfterLeave event.
dev:ssr-logslogsClientCalled with an array of server-side logs that have been passed to the client.
page:view-transition:starttransitionClientCalled after document.startViewTransition is called when experimental viewTransition support is enabled.

Nuxt Hooks (build time)

HookArgumentsDescription
kit:compatibilitycompatibility, issuesAllows extending compatibility checks.
readynuxtCalled after Nuxt initialization, when the Nuxt instance is ready to work.
closenuxtCalled when Nuxt instance is gracefully closing.
restartTo be called to restart the current Nuxt instance.
modules:before-Called during Nuxt initialization, before installing user modules.
modules:done-Called during Nuxt initialization, after installing user modules.
app:resolveappCalled after resolving the app instance.
app:templatesappCalled during NuxtApp generation, to allow customizing, modifying or adding new files to the build directory.
app:templatesGeneratedappCalled after templates are compiled into the virtual file system (vfs).
build:before-Called before Nuxt bundle builder.
build:done-Called after Nuxt bundle builder is complete.
build:manifestmanifestCalled during the manifest build by Vite and webpack.
builder:generateAppoptionsCalled before generating the app.
builder:watchevent, pathCalled at build time in development when the watcher spots a change.
pages:extendpagesCalled after pages routes are resolved.
pages:routerOptions{ files: Array<{ path: string, optional?: boolean }> }Called when resolving router.options files.
server:devHandlerhandlerCalled when the dev middleware is being registered on the Nitro dev server.
imports:sourcespresetsCalled at setup allowing modules to extend sources.
imports:extendimportsCalled at setup allowing modules to extend imports.
imports:contextcontextCalled when the unimport context is created.
imports:dirsdirsAllows extending import directories.
components:dirsdirsCalled within app:resolve allowing to extend the directories that are scanned for auto-importable components.
components:extendcomponentsAllows extending new components.
nitro:confignitroConfigCalled before initializing Nitro, allowing customization of Nitro's configuration.
nitro:initnitroCalled after Nitro is initialized, allows registering Nitro hooks and interacting directly with Nitro.
nitro:build:beforenitroCalled before building the Nitro instance.
nitro:build:public-assetsnitroCalled after copying public assets, allows modifying public assets before Nitro server is built.
prerender:routesctxAllows extending the routes to be pre-rendered.
build:errorerrorCalled when an error occurs at build time.
prepare:typesoptionsCalled before Nuxi writes .nuxt/tsconfig.json and .nuxt/nuxt.d.ts, allowing addition of custom references and declarations.
listenlistenerServer, listenerCalled when the dev server is loading.
schema:extendschemasAllows extending default schemas.
schema:resolvedschemaAllows extending resolved schema.
schema:beforeWriteschemaCalled before writing the given schema.
schema:written-Called after the schema is written.
vite:extendviteBuildContextAllows to extend Vite default context.
vite:extendConfigviteInlineConfig, envAllows to extend Vite default config.
vite:configResolvedviteInlineConfig, envAllows to read the resolved Vite config.
vite:serverCreatedviteServer, envCalled when the Vite server is created.
vite:compiled-Called after Vite server is compiled.
webpack:configwebpackConfigsCalled before configuring the webpack compiler.
webpack:configResolvedwebpackConfigsAllows to read the resolved webpack config.
webpack:compileoptionsCalled right before compilation.
webpack:compiledoptionsCalled after resources are loaded.
webpack:changeshortPathCalled on change on webpackBar.
webpack:error-Called on done if has errors on webpackBar.
webpack:done-Called on allDone on webpackBar.
webpack:progressstatesArrayCalled on progress on webpackBar.

Nitro App Hooks (runtime, server-side)

HookArgumentsDescriptionTypes
dev:ssr-logsCalled at the end of a request cycle with an array of server-side logs.Server
render:responseresponse,Called before sending the response.response, event
render:htmlhtml,Called before constructing the HTML.html, event
render:islandislandResponse,Called before constructing the island HTML.islandResponse, event, islandContext
close-Called when Nitro is closed.-
errorerror,Called when an error occurs.error, event
requesteventCalled when a request is received.event
beforeResponseevent,Called before sending the response.event, unknown
afterResponseevent,Called after sending the response.event, unknown

This table format organizes the provided hooks into a clear and structured layout for easy reference and understanding.

Import meta

import.meta object เป็นวิธีที่ใช้ในโมดูล ES เพื่อเข้าถึงข้อมูลเกี่ยวกับโค้ดที่ import หรือคอมไพล์โดยใช้ ES-module และมีการใช้งานในเอกสารของ Nuxt เพื่อตรวจสอบว่าโค้ดกำลังทำงานอยู่ฝั่งไคลเอ็นต์หรือเซิร์ฟเวอร์บางครั้งด้วยครับ

Runtime (App) Properties

PropertyTypeคำอธิบาย
import.meta.clientbooleanเป็น true เมื่อถูกประเมินในฝั่งไคลเอ็นต์
import.meta.browserbooleanเป็น true เมื่อถูกประเมินในฝั่งไคลเอ็นต์ (เหมือนกับ import.meta.client)
import.meta.serverbooleanเป็น true เมื่อถูกประเมินในฝั่งเซิร์ฟเวอร์
import.meta.nitrobooleanเป็น true เมื่อถูกประเมินในฝั่งเซิร์ฟเวอร์ (เหมือนกับ import.meta.server)
import.meta.devbooleanเป็น true เมื่อทำงานบนเซิร์ฟเวอร์ Nuxt dev
import.meta.testbooleanเป็น true เมื่อทำงานในบริบทของการทดสอบ
import.meta.prerenderbooleanเป็น true เมื่อทำการเรนเดอร์ HTML บนเซิร์ฟเวอร์ในขั้นตอน prerender ของการสร้าง

Builder Properties

PropertyTypeคำอธิบาย
import.meta.envobjectเทียบเท่ากับ process.env
import.meta.urlstringเส้นทางที่สามารถใช้ทำให้เข้าถึงได้สำหรับไฟล์ปัจจุบัน

Released under the MIT License