@nuxt/docs 0.0.0 → 3.17.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.navigation.yml +2 -0
- package/1.getting-started/.navigation.yml +3 -0
- package/1.getting-started/01.introduction.md +81 -0
- package/1.getting-started/02.installation.md +109 -0
- package/1.getting-started/03.configuration.md +226 -0
- package/1.getting-started/04.views.md +163 -0
- package/1.getting-started/05.assets.md +48 -0
- package/1.getting-started/06.styling.md +565 -0
- package/1.getting-started/07.routing.md +149 -0
- package/1.getting-started/08.seo-meta.md +360 -0
- package/1.getting-started/09.transitions.md +473 -0
- package/1.getting-started/10.data-fetching.md +795 -0
- package/1.getting-started/11.state-management.md +223 -0
- package/1.getting-started/12.error-handling.md +233 -0
- package/1.getting-started/13.server.md +94 -0
- package/1.getting-started/14.layers.md +92 -0
- package/1.getting-started/15.prerendering.md +194 -0
- package/1.getting-started/16.deployment.md +130 -0
- package/1.getting-started/17.testing.md +728 -0
- package/1.getting-started/18.upgrade.md +997 -0
- package/2.guide/.navigation.yml +2 -0
- package/2.guide/0.index.md +22 -0
- package/2.guide/1.concepts/.navigation.yml +3 -0
- package/2.guide/1.concepts/1.auto-imports.md +205 -0
- package/2.guide/1.concepts/10.nuxt-lifecycle.md +141 -0
- package/2.guide/1.concepts/2.vuejs-development.md +103 -0
- package/2.guide/1.concepts/3.rendering.md +255 -0
- package/2.guide/1.concepts/4.server-engine.md +62 -0
- package/2.guide/1.concepts/5.modules.md +48 -0
- package/2.guide/1.concepts/7.esm.md +299 -0
- package/2.guide/1.concepts/8.typescript.md +97 -0
- package/2.guide/1.concepts/9.code-style.md +22 -0
- package/2.guide/2.directory-structure/.navigation.yml +3 -0
- package/2.guide/2.directory-structure/0.nuxt.md +20 -0
- package/2.guide/2.directory-structure/0.output.md +18 -0
- package/2.guide/2.directory-structure/1.assets.md +16 -0
- package/2.guide/2.directory-structure/1.components.md +608 -0
- package/2.guide/2.directory-structure/1.composables.md +121 -0
- package/2.guide/2.directory-structure/1.content.md +64 -0
- package/2.guide/2.directory-structure/1.layouts.md +180 -0
- package/2.guide/2.directory-structure/1.middleware.md +209 -0
- package/2.guide/2.directory-structure/1.modules.md +66 -0
- package/2.guide/2.directory-structure/1.node_modules.md +12 -0
- package/2.guide/2.directory-structure/1.pages.md +440 -0
- package/2.guide/2.directory-structure/1.plugins.md +299 -0
- package/2.guide/2.directory-structure/1.public.md +27 -0
- package/2.guide/2.directory-structure/1.server.md +546 -0
- package/2.guide/2.directory-structure/1.shared.md +104 -0
- package/2.guide/2.directory-structure/1.utils.md +49 -0
- package/2.guide/2.directory-structure/2.env.md +75 -0
- package/2.guide/2.directory-structure/2.gitignore.md +37 -0
- package/2.guide/2.directory-structure/2.nuxtignore.md +36 -0
- package/2.guide/2.directory-structure/2.nuxtrc.md +50 -0
- package/2.guide/2.directory-structure/3.app-config.md +177 -0
- package/2.guide/2.directory-structure/3.app.md +72 -0
- package/2.guide/2.directory-structure/3.error.md +55 -0
- package/2.guide/2.directory-structure/3.nuxt-config.md +34 -0
- package/2.guide/2.directory-structure/3.package.md +32 -0
- package/2.guide/2.directory-structure/3.tsconfig.md +24 -0
- package/2.guide/3.going-further/.navigation.yml +3 -0
- package/2.guide/3.going-further/1.experimental-features.md +689 -0
- package/2.guide/3.going-further/1.features.md +103 -0
- package/2.guide/3.going-further/1.internals.md +81 -0
- package/2.guide/3.going-further/10.runtime-config.md +174 -0
- package/2.guide/3.going-further/11.nightly-release-channel.md +68 -0
- package/2.guide/3.going-further/2.hooks.md +98 -0
- package/2.guide/3.going-further/3.modules.md +811 -0
- package/2.guide/3.going-further/4.kit.md +51 -0
- package/2.guide/3.going-further/6.nuxt-app.md +64 -0
- package/2.guide/3.going-further/7.layers.md +227 -0
- package/2.guide/3.going-further/9.debugging.md +115 -0
- package/2.guide/3.going-further/index.md +4 -0
- package/2.guide/4.recipes/.navigation.yml +3 -0
- package/2.guide/4.recipes/1.custom-routing.md +181 -0
- package/2.guide/4.recipes/2.vite-plugin.md +65 -0
- package/2.guide/4.recipes/3.custom-usefetch.md +125 -0
- package/2.guide/4.recipes/4.sessions-and-authentication.md +203 -0
- package/3.api/.navigation.yml +3 -0
- package/3.api/1.components/.navigation.yml +3 -0
- package/3.api/1.components/1.client-only.md +76 -0
- package/3.api/1.components/1.dev-only.md +51 -0
- package/3.api/1.components/1.nuxt-client-fallback.md +80 -0
- package/3.api/1.components/10.nuxt-picture.md +27 -0
- package/3.api/1.components/11.teleports.md +40 -0
- package/3.api/1.components/12.nuxt-route-announcer.md +56 -0
- package/3.api/1.components/13.nuxt-time.md +173 -0
- package/3.api/1.components/2.nuxt-page.md +154 -0
- package/3.api/1.components/3.nuxt-layout.md +156 -0
- package/3.api/1.components/4.nuxt-link.md +322 -0
- package/3.api/1.components/5.nuxt-loading-indicator.md +50 -0
- package/3.api/1.components/6.nuxt-error-boundary.md +65 -0
- package/3.api/1.components/7.nuxt-welcome.md +25 -0
- package/3.api/1.components/8.nuxt-island.md +70 -0
- package/3.api/1.components/9.nuxt-img.md +43 -0
- package/3.api/2.composables/.navigation.yml +3 -0
- package/3.api/2.composables/on-prehydrate.md +60 -0
- package/3.api/2.composables/use-app-config.md +19 -0
- package/3.api/2.composables/use-async-data.md +212 -0
- package/3.api/2.composables/use-cookie.md +233 -0
- package/3.api/2.composables/use-error.md +32 -0
- package/3.api/2.composables/use-fetch.md +217 -0
- package/3.api/2.composables/use-head-safe.md +55 -0
- package/3.api/2.composables/use-head.md +69 -0
- package/3.api/2.composables/use-hydration.md +68 -0
- package/3.api/2.composables/use-lazy-async-data.md +47 -0
- package/3.api/2.composables/use-lazy-fetch.md +55 -0
- package/3.api/2.composables/use-loading-indicator.md +77 -0
- package/3.api/2.composables/use-nuxt-app.md +294 -0
- package/3.api/2.composables/use-nuxt-data.md +112 -0
- package/3.api/2.composables/use-preview-mode.md +118 -0
- package/3.api/2.composables/use-request-event.md +23 -0
- package/3.api/2.composables/use-request-fetch.md +52 -0
- package/3.api/2.composables/use-request-header.md +34 -0
- package/3.api/2.composables/use-request-headers.md +37 -0
- package/3.api/2.composables/use-request-url.md +41 -0
- package/3.api/2.composables/use-response-header.md +48 -0
- package/3.api/2.composables/use-route-announcer.md +60 -0
- package/3.api/2.composables/use-route.md +52 -0
- package/3.api/2.composables/use-router.md +92 -0
- package/3.api/2.composables/use-runtime-config.md +142 -0
- package/3.api/2.composables/use-runtime-hook.md +43 -0
- package/3.api/2.composables/use-seo-meta.md +80 -0
- package/3.api/2.composables/use-server-seo-meta.md +27 -0
- package/3.api/2.composables/use-state.md +48 -0
- package/3.api/3.utils/$fetch.md +98 -0
- package/3.api/3.utils/.navigation.yml +3 -0
- package/3.api/3.utils/abort-navigation.md +73 -0
- package/3.api/3.utils/add-route-middleware.md +88 -0
- package/3.api/3.utils/call-once.md +92 -0
- package/3.api/3.utils/clear-error.md +29 -0
- package/3.api/3.utils/clear-nuxt-data.md +23 -0
- package/3.api/3.utils/clear-nuxt-state.md +23 -0
- package/3.api/3.utils/create-error.md +55 -0
- package/3.api/3.utils/define-nuxt-component.md +53 -0
- package/3.api/3.utils/define-nuxt-route-middleware.md +67 -0
- package/3.api/3.utils/define-page-meta.md +234 -0
- package/3.api/3.utils/define-route-rules.md +52 -0
- package/3.api/3.utils/navigate-to.md +230 -0
- package/3.api/3.utils/on-before-route-leave.md +11 -0
- package/3.api/3.utils/on-before-route-update.md +11 -0
- package/3.api/3.utils/on-nuxt-ready.md +25 -0
- package/3.api/3.utils/prefetch-components.md +28 -0
- package/3.api/3.utils/preload-components.md +23 -0
- package/3.api/3.utils/preload-route-components.md +41 -0
- package/3.api/3.utils/prerender-routes.md +46 -0
- package/3.api/3.utils/refresh-cookie.md +46 -0
- package/3.api/3.utils/refresh-nuxt-data.md +91 -0
- package/3.api/3.utils/reload-nuxt-app.md +74 -0
- package/3.api/3.utils/set-page-layout.md +24 -0
- package/3.api/3.utils/set-response-status.md +36 -0
- package/3.api/3.utils/show-error.md +31 -0
- package/3.api/3.utils/update-app-config.md +27 -0
- package/3.api/4.commands/.navigation.yml +3 -0
- package/3.api/4.commands/add.md +112 -0
- package/3.api/4.commands/analyze.md +41 -0
- package/3.api/4.commands/build-module.md +42 -0
- package/3.api/4.commands/build.md +46 -0
- package/3.api/4.commands/cleanup.md +38 -0
- package/3.api/4.commands/dev.md +59 -0
- package/3.api/4.commands/devtools.md +38 -0
- package/3.api/4.commands/generate.md +41 -0
- package/3.api/4.commands/info.md +33 -0
- package/3.api/4.commands/init.md +46 -0
- package/3.api/4.commands/module.md +84 -0
- package/3.api/4.commands/prepare.md +36 -0
- package/3.api/4.commands/preview.md +43 -0
- package/3.api/4.commands/typecheck.md +42 -0
- package/3.api/4.commands/upgrade.md +37 -0
- package/3.api/5.kit/.navigation.yml +3 -0
- package/3.api/5.kit/1.modules.md +172 -0
- package/3.api/5.kit/10.runtime-config.md +27 -0
- package/3.api/5.kit/10.templates.md +283 -0
- package/3.api/5.kit/11.nitro.md +409 -0
- package/3.api/5.kit/12.resolving.md +268 -0
- package/3.api/5.kit/13.logging.md +65 -0
- package/3.api/5.kit/14.builder.md +491 -0
- package/3.api/5.kit/15.examples.md +41 -0
- package/3.api/5.kit/2.programmatic.md +125 -0
- package/3.api/5.kit/3.compatibility.md +230 -0
- package/3.api/5.kit/4.autoimports.md +144 -0
- package/3.api/5.kit/5.components.md +127 -0
- package/3.api/5.kit/6.context.md +130 -0
- package/3.api/5.kit/7.pages.md +295 -0
- package/3.api/5.kit/8.layout.md +80 -0
- package/3.api/5.kit/9.plugins.md +263 -0
- package/3.api/6.advanced/.navigation.yml +1 -0
- package/3.api/6.advanced/1.hooks.md +105 -0
- package/3.api/6.advanced/2.import-meta.md +60 -0
- package/3.api/6.nuxt-config.md +12 -0
- package/3.api/index.md +31 -0
- package/5.community/.navigation.yml +3 -0
- package/5.community/2.getting-help.md +48 -0
- package/5.community/3.reporting-bugs.md +50 -0
- package/5.community/4.contribution.md +205 -0
- package/5.community/5.framework-contribution.md +142 -0
- package/5.community/6.roadmap.md +79 -0
- package/5.community/7.changelog.md +92 -0
- package/6.bridge/.navigation.yml +3 -0
- package/6.bridge/1.overview.md +137 -0
- package/6.bridge/10.configuration.md +96 -0
- package/6.bridge/2.typescript.md +46 -0
- package/6.bridge/3.bridge-composition-api.md +132 -0
- package/6.bridge/4.plugins-and-middleware.md +65 -0
- package/6.bridge/5.nuxt3-compatible-api.md +204 -0
- package/6.bridge/6.meta.md +117 -0
- package/6.bridge/7.runtime-config.md +38 -0
- package/6.bridge/8.nitro.md +102 -0
- package/6.bridge/9.vite.md +37 -0
- package/7.migration/.navigation.yml +3 -0
- package/7.migration/1.overview.md +24 -0
- package/7.migration/10.bundling.md +28 -0
- package/7.migration/11.server.md +17 -0
- package/7.migration/2.configuration.md +240 -0
- package/7.migration/20.module-authors.md +94 -0
- package/7.migration/3.auto-imports.md +18 -0
- package/7.migration/4.meta.md +127 -0
- package/7.migration/5.plugins-and-middleware.md +80 -0
- package/7.migration/6.pages-and-layouts.md +233 -0
- package/7.migration/7.component-options.md +156 -0
- package/7.migration/8.runtime-config.md +58 -0
- package/LICENSE +21 -0
- package/README.md +11 -0
- package/package.json +16 -4
- package/dist/.gitkeep +0 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: 'prerenderRoutes'
|
|
3
|
+
description: prerenderRoutes hints to Nitro to prerender an additional route.
|
|
4
|
+
links:
|
|
5
|
+
- label: Source
|
|
6
|
+
icon: i-simple-icons-github
|
|
7
|
+
to: https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/app/composables/ssr.ts
|
|
8
|
+
size: xs
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
When prerendering, you can hint to Nitro to prerender additional paths, even if their URLs do not show up in the HTML of the generated page.
|
|
12
|
+
|
|
13
|
+
::important
|
|
14
|
+
`prerenderRoutes` can only be called within the [Nuxt context](/docs/guide/going-further/nuxt-app#the-nuxt-context).
|
|
15
|
+
::
|
|
16
|
+
|
|
17
|
+
::note
|
|
18
|
+
`prerenderRoutes` has to be executed during prerendering. If the `prerenderRoutes` is used in dynamic pages/routes which are not prerendered, then it will not be executed.
|
|
19
|
+
::
|
|
20
|
+
|
|
21
|
+
```js
|
|
22
|
+
const route = useRoute()
|
|
23
|
+
|
|
24
|
+
prerenderRoutes('/')
|
|
25
|
+
prerenderRoutes(['/', '/about'])
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
::note
|
|
29
|
+
In the browser, or if called outside prerendering, `prerenderRoutes` will have no effect.
|
|
30
|
+
::
|
|
31
|
+
|
|
32
|
+
You can even prerender API routes which is particularly useful for full statically generated sites (SSG) because you can then `$fetch` data as if you have an available server!
|
|
33
|
+
|
|
34
|
+
```js
|
|
35
|
+
prerenderRoutes('/api/content/article/name-of-article')
|
|
36
|
+
|
|
37
|
+
// Somewhere later in App
|
|
38
|
+
const articleContent = await $fetch('/api/content/article/name-of-article', {
|
|
39
|
+
responseType: 'json',
|
|
40
|
+
})
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
::warning
|
|
44
|
+
Prerendered API routes in production may not return the expected response headers, depending on the provider you deploy to. For example, a JSON response might be served with an `application/octet-stream` content type.
|
|
45
|
+
Always manually set `responseType` when fetching prerendered API routes.
|
|
46
|
+
::
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "refreshCookie"
|
|
3
|
+
description: "Refresh useCookie values manually when a cookie has changed"
|
|
4
|
+
navigation:
|
|
5
|
+
badge: New
|
|
6
|
+
links:
|
|
7
|
+
- label: Source
|
|
8
|
+
icon: i-simple-icons-github
|
|
9
|
+
to: https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/app/composables/cookie.ts
|
|
10
|
+
size: xs
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
::important
|
|
14
|
+
This utility is available since [Nuxt v3.10](/blog/v3-10).
|
|
15
|
+
::
|
|
16
|
+
|
|
17
|
+
## Purpose
|
|
18
|
+
|
|
19
|
+
The `refreshCookie` function is designed to refresh cookie value returned by `useCookie`.
|
|
20
|
+
|
|
21
|
+
This is useful for updating the `useCookie` ref when we know the new cookie value has been set in the browser.
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
```vue [app.vue]
|
|
26
|
+
<script setup lang="ts">
|
|
27
|
+
const tokenCookie = useCookie('token')
|
|
28
|
+
|
|
29
|
+
const login = async (username, password) => {
|
|
30
|
+
const token = await $fetch('/api/token', { ... }) // Sets `token` cookie on response
|
|
31
|
+
refreshCookie('token')
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const loggedIn = computed(() => !!tokenCookie.value)
|
|
35
|
+
</script>
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
::note{to="/docs/guide/going-further/experimental-features#cookiestore"}
|
|
39
|
+
You can enable experimental `cookieStore` option to automatically refresh `useCookie` value when cookie changes in the browser.
|
|
40
|
+
::
|
|
41
|
+
|
|
42
|
+
## Type
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
refreshCookie(name: string): void
|
|
46
|
+
```
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: 'refreshNuxtData'
|
|
3
|
+
description: Refresh all or specific asyncData instances in Nuxt
|
|
4
|
+
links:
|
|
5
|
+
- label: Source
|
|
6
|
+
icon: i-simple-icons-github
|
|
7
|
+
to: https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/app/composables/asyncData.ts
|
|
8
|
+
size: xs
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
`refreshNuxtData` is used to refetch all or specific `asyncData` instances, including those from [`useAsyncData`](/docs/api/composables/use-async-data), [`useLazyAsyncData`](/docs/api/composables/use-lazy-async-data), [`useFetch`](/docs/api/composables/use-fetch), and [`useLazyFetch`](/docs/api/composables/use-lazy-fetch).
|
|
12
|
+
|
|
13
|
+
::note
|
|
14
|
+
If your component is cached by `<KeepAlive>` and enters a deactivated state, the `asyncData` inside the component will still be refetched until the component is unmounted.
|
|
15
|
+
::
|
|
16
|
+
|
|
17
|
+
## Type
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
refreshNuxtData(keys?: string | string[])
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Parameters
|
|
24
|
+
|
|
25
|
+
* `keys`: A single string or an array of strings as `keys` that are used to fetch the data. This parameter is **optional**. All [`useAsyncData`](/docs/api/composables/use-async-data) and [`useFetch`](/docs/api/composables/use-fetch) keys are re-fetched when no `keys` are explicitly specified.
|
|
26
|
+
|
|
27
|
+
## Return Values
|
|
28
|
+
|
|
29
|
+
`refreshNuxtData` returns a promise, resolving when all or specific `asyncData` instances have been refreshed.
|
|
30
|
+
|
|
31
|
+
## Examples
|
|
32
|
+
|
|
33
|
+
### Refresh All Data
|
|
34
|
+
|
|
35
|
+
This example below refreshes all data being fetched using `useAsyncData` and `useFetch` in Nuxt application.
|
|
36
|
+
|
|
37
|
+
```vue [pages/some-page.vue]
|
|
38
|
+
<script setup lang="ts">
|
|
39
|
+
const refreshing = ref(false)
|
|
40
|
+
|
|
41
|
+
async function refreshAll () {
|
|
42
|
+
refreshing.value = true
|
|
43
|
+
try {
|
|
44
|
+
await refreshNuxtData()
|
|
45
|
+
} finally {
|
|
46
|
+
refreshing.value = false
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
</script>
|
|
50
|
+
|
|
51
|
+
<template>
|
|
52
|
+
<div>
|
|
53
|
+
<button :disabled="refreshing" @click="refreshAll">
|
|
54
|
+
Refetch All Data
|
|
55
|
+
</button>
|
|
56
|
+
</div>
|
|
57
|
+
</template>
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Refresh Specific Data
|
|
61
|
+
|
|
62
|
+
This example below refreshes only data where the key matches to `count` and `user`.
|
|
63
|
+
|
|
64
|
+
```vue [pages/some-page.vue]
|
|
65
|
+
<script setup lang="ts">
|
|
66
|
+
const refreshing = ref(false)
|
|
67
|
+
|
|
68
|
+
async function refresh () {
|
|
69
|
+
refreshing.value = true
|
|
70
|
+
try {
|
|
71
|
+
// you could also pass an array of keys to refresh multiple data
|
|
72
|
+
await refreshNuxtData(['count', 'user'])
|
|
73
|
+
} finally {
|
|
74
|
+
refreshing.value = false
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
</script>
|
|
78
|
+
|
|
79
|
+
<template>
|
|
80
|
+
<div v-if="refreshing">
|
|
81
|
+
Loading
|
|
82
|
+
</div>
|
|
83
|
+
<button @click="refresh">Refresh</button>
|
|
84
|
+
</template>
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
::note
|
|
88
|
+
If you have access to the `asyncData` instance, it is recommended to use its `refresh` or `execute` method as the preferred way to refetch the data.
|
|
89
|
+
::
|
|
90
|
+
|
|
91
|
+
:read-more{to="/docs/getting-started/data-fetching"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: 'reloadNuxtApp'
|
|
3
|
+
description: reloadNuxtApp will perform a hard reload of the page.
|
|
4
|
+
links:
|
|
5
|
+
- label: Source
|
|
6
|
+
icon: i-simple-icons-github
|
|
7
|
+
to: https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/app/composables/chunk.ts
|
|
8
|
+
size: xs
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
::note
|
|
12
|
+
`reloadNuxtApp` will perform a hard reload of your app, re-requesting a page and its dependencies from the server.
|
|
13
|
+
::
|
|
14
|
+
|
|
15
|
+
By default, it will also save the current `state` of your app (that is, any state you could access with `useState`).
|
|
16
|
+
|
|
17
|
+
::read-more{to="/docs/guide/going-further/experimental-features#restorestate" icon="i-lucide-star"}
|
|
18
|
+
You can enable experimental restoration of this state by enabling the `experimental.restoreState` option in your `nuxt.config` file.
|
|
19
|
+
::
|
|
20
|
+
|
|
21
|
+
## Type
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
reloadNuxtApp(options?: ReloadNuxtAppOptions)
|
|
25
|
+
|
|
26
|
+
interface ReloadNuxtAppOptions {
|
|
27
|
+
ttl?: number
|
|
28
|
+
force?: boolean
|
|
29
|
+
path?: string
|
|
30
|
+
persistState?: boolean
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### `options` (optional)
|
|
35
|
+
|
|
36
|
+
**Type**: `ReloadNuxtAppOptions`
|
|
37
|
+
|
|
38
|
+
An object accepting the following properties:
|
|
39
|
+
|
|
40
|
+
- `path` (optional)
|
|
41
|
+
|
|
42
|
+
**Type**: `string`
|
|
43
|
+
|
|
44
|
+
**Default**: `window.location.pathname`
|
|
45
|
+
|
|
46
|
+
The path to reload (defaulting to the current path). If this is different from the current window location it
|
|
47
|
+
will trigger a navigation and add an entry in the browser history.
|
|
48
|
+
|
|
49
|
+
- `ttl` (optional)
|
|
50
|
+
|
|
51
|
+
**Type**: `number`
|
|
52
|
+
|
|
53
|
+
**Default**: `10000`
|
|
54
|
+
|
|
55
|
+
The number of milliseconds in which to ignore future reload requests. If called again within this time period,
|
|
56
|
+
`reloadNuxtApp` will not reload your app to avoid reload loops.
|
|
57
|
+
|
|
58
|
+
- `force` (optional)
|
|
59
|
+
|
|
60
|
+
**Type**: `boolean`
|
|
61
|
+
|
|
62
|
+
**Default**: `false`
|
|
63
|
+
|
|
64
|
+
This option allows bypassing reload loop protection entirely, forcing a reload even if one has occurred within
|
|
65
|
+
the previously specified TTL.
|
|
66
|
+
|
|
67
|
+
- `persistState` (optional)
|
|
68
|
+
|
|
69
|
+
**Type**: `boolean`
|
|
70
|
+
|
|
71
|
+
**Default**: `false`
|
|
72
|
+
|
|
73
|
+
Whether to dump the current Nuxt state to sessionStorage (as `nuxt:reload:state`). By default this will have no
|
|
74
|
+
effect on reload unless `experimental.restoreState` is also set, or unless you handle restoring the state yourself.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: 'setPageLayout'
|
|
3
|
+
description: setPageLayout allows you to dynamically change the layout of a page.
|
|
4
|
+
links:
|
|
5
|
+
- label: Source
|
|
6
|
+
icon: i-simple-icons-github
|
|
7
|
+
to: https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/app/composables/router.ts
|
|
8
|
+
size: xs
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
::important
|
|
12
|
+
`setPageLayout` allows you to dynamically change the layout of a page. It relies on access to the Nuxt context and therefore can only be called within the [Nuxt context](/docs/guide/going-further/nuxt-app#the-nuxt-context).
|
|
13
|
+
::
|
|
14
|
+
|
|
15
|
+
```ts [middleware/custom-layout.ts]
|
|
16
|
+
export default defineNuxtRouteMiddleware((to) => {
|
|
17
|
+
// Set the layout on the route you are navigating _to_
|
|
18
|
+
setPageLayout('other')
|
|
19
|
+
})
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
::note
|
|
23
|
+
If you choose to set the layout dynamically on the server side, you _must_ do so before the layout is rendered by Vue (that is, within a plugin or route middleware) to avoid a hydration mismatch.
|
|
24
|
+
::
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: 'setResponseStatus'
|
|
3
|
+
description: setResponseStatus sets the statusCode (and optionally the statusMessage) of the response.
|
|
4
|
+
links:
|
|
5
|
+
- label: Source
|
|
6
|
+
icon: i-simple-icons-github
|
|
7
|
+
to: https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/app/composables/ssr.ts
|
|
8
|
+
size: xs
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
Nuxt provides composables and utilities for first-class server-side-rendering support.
|
|
12
|
+
|
|
13
|
+
`setResponseStatus` sets the statusCode (and optionally the statusMessage) of the response.
|
|
14
|
+
|
|
15
|
+
::important
|
|
16
|
+
`setResponseStatus` can only be called in the [Nuxt context](/docs/guide/going-further/nuxt-app#the-nuxt-context).
|
|
17
|
+
::
|
|
18
|
+
|
|
19
|
+
```js
|
|
20
|
+
const event = useRequestEvent()
|
|
21
|
+
|
|
22
|
+
// event will be undefined in the browser
|
|
23
|
+
if (event) {
|
|
24
|
+
// Set the status code to 404 for a custom 404 page
|
|
25
|
+
setResponseStatus(event, 404)
|
|
26
|
+
|
|
27
|
+
// Set the status message as well
|
|
28
|
+
setResponseStatus(event, 404, 'Page Not Found')
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
::note
|
|
33
|
+
In the browser, `setResponseStatus` will have no effect.
|
|
34
|
+
::
|
|
35
|
+
|
|
36
|
+
:read-more{to="/docs/getting-started/error-handling"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: 'showError'
|
|
3
|
+
description: Nuxt provides a quick and simple way to show a full screen error page if needed.
|
|
4
|
+
links:
|
|
5
|
+
- label: Source
|
|
6
|
+
icon: i-simple-icons-github
|
|
7
|
+
to: https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/app/composables/error.ts
|
|
8
|
+
size: xs
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
Within the [Nuxt context](/docs/guide/going-further/nuxt-app#the-nuxt-context) you can use `showError` to show an error.
|
|
12
|
+
|
|
13
|
+
**Parameters:**
|
|
14
|
+
|
|
15
|
+
- `error`: `string | Error | Partial<{ cause, data, message, name, stack, statusCode, statusMessage }>`
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
showError("😱 Oh no, an error has been thrown.")
|
|
19
|
+
showError({
|
|
20
|
+
statusCode: 404,
|
|
21
|
+
statusMessage: "Page Not Found"
|
|
22
|
+
})
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
The error is set in the state using [`useError()`](/docs/api/composables/use-error) to create a reactive and SSR-friendly shared error state across components.
|
|
26
|
+
|
|
27
|
+
::tip
|
|
28
|
+
`showError` calls the `app:error` hook.
|
|
29
|
+
::
|
|
30
|
+
|
|
31
|
+
:read-more{to="/docs/getting-started/error-handling"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: 'updateAppConfig'
|
|
3
|
+
description: 'Update the App Config at runtime.'
|
|
4
|
+
links:
|
|
5
|
+
- label: Source
|
|
6
|
+
icon: i-simple-icons-github
|
|
7
|
+
to: https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/app/config.ts
|
|
8
|
+
size: xs
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
::note
|
|
12
|
+
Updates the [`app.config`](/docs/guide/directory-structure/app-config) using deep assignment. Existing (nested) properties will be preserved.
|
|
13
|
+
::
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
const appConfig = useAppConfig() // { foo: 'bar' }
|
|
19
|
+
|
|
20
|
+
const newAppConfig = { foo: 'baz' }
|
|
21
|
+
|
|
22
|
+
updateAppConfig(newAppConfig)
|
|
23
|
+
|
|
24
|
+
console.log(appConfig) // { foo: 'baz' }
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
:read-more{to="/docs/guide/directory-structure/app-config"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "nuxi add"
|
|
3
|
+
description: "Scaffold an entity into your Nuxt application."
|
|
4
|
+
links:
|
|
5
|
+
- label: Source
|
|
6
|
+
icon: i-simple-icons-github
|
|
7
|
+
to: https://github.com/nuxt/cli/blob/main/packages/nuxi/src/commands/add.ts
|
|
8
|
+
size: xs
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
<!--add-cmd-->
|
|
12
|
+
```bash [Terminal]
|
|
13
|
+
npx nuxi add <TEMPLATE> <NAME> [--cwd=<directory>] [--logLevel=<silent|info|verbose>] [--force]
|
|
14
|
+
```
|
|
15
|
+
<!--/add-cmd-->
|
|
16
|
+
|
|
17
|
+
### Arguments
|
|
18
|
+
|
|
19
|
+
<!--add-args-->
|
|
20
|
+
Argument | Description
|
|
21
|
+
--- | ---
|
|
22
|
+
`TEMPLATE` | Specify which template to generate (options: <api\|plugin\|component\|composable\|middleware\|layout\|page\|layer>)
|
|
23
|
+
`NAME` | Specify name of the generated file
|
|
24
|
+
<!--/add-args-->
|
|
25
|
+
|
|
26
|
+
### Options
|
|
27
|
+
|
|
28
|
+
<!--add-opts-->
|
|
29
|
+
Option | Default | Description
|
|
30
|
+
--- | --- | ---
|
|
31
|
+
`--cwd=<directory>` | `.` | Specify the working directory
|
|
32
|
+
`--logLevel=<silent\|info\|verbose>` | | Specify build-time log level
|
|
33
|
+
`--force` | `false` | Force override file if it already exists
|
|
34
|
+
<!--/add-opts-->
|
|
35
|
+
|
|
36
|
+
**Modifiers:**
|
|
37
|
+
|
|
38
|
+
Some templates support additional modifier flags to add a suffix (like `.client` or `.get`) to their name.
|
|
39
|
+
|
|
40
|
+
```bash [Terminal]
|
|
41
|
+
# Generates `/plugins/sockets.client.ts`
|
|
42
|
+
npx nuxi add plugin sockets --client
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## `nuxi add component`
|
|
46
|
+
|
|
47
|
+
* Modifier flags: `--mode client|server` or `--client` or `--server`
|
|
48
|
+
|
|
49
|
+
```bash [Terminal]
|
|
50
|
+
# Generates `components/TheHeader.vue`
|
|
51
|
+
npx nuxi add component TheHeader
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## `nuxi add composable`
|
|
55
|
+
|
|
56
|
+
```bash [Terminal]
|
|
57
|
+
# Generates `composables/foo.ts`
|
|
58
|
+
npx nuxi add composable foo
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## `nuxi add layout`
|
|
62
|
+
|
|
63
|
+
```bash [Terminal]
|
|
64
|
+
# Generates `layouts/custom.vue`
|
|
65
|
+
npx nuxi add layout custom
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## `nuxi add plugin`
|
|
69
|
+
|
|
70
|
+
* Modifier flags: `--mode client|server` or `--client`or `--server`
|
|
71
|
+
|
|
72
|
+
```bash [Terminal]
|
|
73
|
+
# Generates `plugins/analytics.ts`
|
|
74
|
+
npx nuxi add plugin analytics
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## `nuxi add page`
|
|
78
|
+
|
|
79
|
+
```bash [Terminal]
|
|
80
|
+
# Generates `pages/about.vue`
|
|
81
|
+
npx nuxi add page about
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
```bash [Terminal]
|
|
85
|
+
# Generates `pages/category/[id].vue`
|
|
86
|
+
npx nuxi add page "category/[id]"
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## `nuxi add middleware`
|
|
90
|
+
|
|
91
|
+
* Modifier flags: `--global`
|
|
92
|
+
|
|
93
|
+
```bash [Terminal]
|
|
94
|
+
# Generates `middleware/auth.ts`
|
|
95
|
+
npx nuxi add middleware auth
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## `nuxi add api`
|
|
99
|
+
|
|
100
|
+
* Modifier flags: `--method` (can accept `connect`, `delete`, `get`, `head`, `options`, `patch`, `post`, `put` or `trace`) or alternatively you can directly use `--get`, `--post`, etc.
|
|
101
|
+
|
|
102
|
+
```bash [Terminal]
|
|
103
|
+
# Generates `server/api/hello.ts`
|
|
104
|
+
npx nuxi add api hello
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## `nuxi add layer`
|
|
108
|
+
|
|
109
|
+
```bash [Terminal]
|
|
110
|
+
# Generates `layers/subscribe/nuxt.config.ts`
|
|
111
|
+
npx nuxi add layer subscribe
|
|
112
|
+
```
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "nuxi analyze"
|
|
3
|
+
description: "Analyze the production bundle or your Nuxt application."
|
|
4
|
+
links:
|
|
5
|
+
- label: Source
|
|
6
|
+
icon: i-simple-icons-github
|
|
7
|
+
to: https://github.com/nuxt/cli/blob/main/packages/nuxi/src/commands/analyze.ts
|
|
8
|
+
size: xs
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
<!--analyze-cmd-->
|
|
12
|
+
```bash [Terminal]
|
|
13
|
+
npx nuxi analyze [ROOTDIR] [--cwd=<directory>] [--logLevel=<silent|info|verbose>] [--dotenv] [--name=<name>] [--no-serve]
|
|
14
|
+
```
|
|
15
|
+
<!--/analyze-cmd-->
|
|
16
|
+
|
|
17
|
+
The `analyze` command builds Nuxt and analyzes the production bundle (experimental).
|
|
18
|
+
|
|
19
|
+
## Arguments
|
|
20
|
+
|
|
21
|
+
<!--analyze-args-->
|
|
22
|
+
Argument | Description
|
|
23
|
+
--- | ---
|
|
24
|
+
`ROOTDIR="."` | Specifies the working directory (default: `.`)
|
|
25
|
+
<!--/analyze-args-->
|
|
26
|
+
|
|
27
|
+
## Options
|
|
28
|
+
|
|
29
|
+
<!--analyze-opts-->
|
|
30
|
+
Option | Default | Description
|
|
31
|
+
--- | --- | ---
|
|
32
|
+
`--cwd=<directory>` | | Specify the working directory, this takes precedence over ROOTDIR (default: `.`)
|
|
33
|
+
`--logLevel=<silent\|info\|verbose>` | | Specify build-time log level
|
|
34
|
+
`--dotenv` | | Path to `.env` file to load, relative to the root directory
|
|
35
|
+
`--name=<name>` | `default` | Name of the analysis
|
|
36
|
+
`--no-serve` | | Skip serving the analysis results
|
|
37
|
+
<!--/analyze-opts-->
|
|
38
|
+
|
|
39
|
+
::note
|
|
40
|
+
This command sets `process.env.NODE_ENV` to `production`.
|
|
41
|
+
::
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: 'nuxi build-module'
|
|
3
|
+
description: 'Nuxt command to build your Nuxt module before publishing.'
|
|
4
|
+
links:
|
|
5
|
+
- label: Source
|
|
6
|
+
icon: i-simple-icons-github
|
|
7
|
+
to: https://github.com/nuxt/module-builder/blob/main/src/cli.ts
|
|
8
|
+
size: xs
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
<!--build-module-cmd-->
|
|
12
|
+
```bash [Terminal]
|
|
13
|
+
npx nuxi build-module [ROOTDIR] [--cwd=<directory>] [--logLevel=<silent|info|verbose>] [--build] [--stub] [--sourcemap] [--prepare]
|
|
14
|
+
```
|
|
15
|
+
<!--/build-module-cmd-->
|
|
16
|
+
|
|
17
|
+
The `build-module` command runs `@nuxt/module-builder` to generate `dist` directory within your `rootDir` that contains the full build for your **nuxt-module**.
|
|
18
|
+
|
|
19
|
+
## Arguments
|
|
20
|
+
|
|
21
|
+
<!--build-module-args-->
|
|
22
|
+
Argument | Description
|
|
23
|
+
--- | ---
|
|
24
|
+
`ROOTDIR="."` | Specifies the working directory (default: `.`)
|
|
25
|
+
<!--/build-module-args-->
|
|
26
|
+
|
|
27
|
+
## Options
|
|
28
|
+
|
|
29
|
+
<!--build-module-opts-->
|
|
30
|
+
Option | Default | Description
|
|
31
|
+
--- | --- | ---
|
|
32
|
+
`--cwd=<directory>` | | Specify the working directory, this takes precedence over ROOTDIR (default: `.`)
|
|
33
|
+
`--logLevel=<silent\|info\|verbose>` | | Specify build-time log level
|
|
34
|
+
`--build` | `false` | Build module for distribution
|
|
35
|
+
`--stub` | `false` | Stub dist instead of actually building it for development
|
|
36
|
+
`--sourcemap` | `false` | Generate sourcemaps
|
|
37
|
+
`--prepare` | `false` | Prepare module for local development
|
|
38
|
+
<!--/build-module-opts-->
|
|
39
|
+
|
|
40
|
+
::read-more{to="https://github.com/nuxt/module-builder" icon="i-simple-icons-github" target="\_blank"}
|
|
41
|
+
Read more about `@nuxt/module-builder`.
|
|
42
|
+
::
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "nuxi build"
|
|
3
|
+
description: "Build your Nuxt application."
|
|
4
|
+
links:
|
|
5
|
+
- label: Source
|
|
6
|
+
icon: i-simple-icons-github
|
|
7
|
+
to: https://github.com/nuxt/cli/blob/main/packages/nuxi/src/commands/build.ts
|
|
8
|
+
size: xs
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
<!--build-cmd-->
|
|
12
|
+
```bash [Terminal]
|
|
13
|
+
npx nuxi build [ROOTDIR] [--cwd=<directory>] [--logLevel=<silent|info|verbose>] [--prerender] [--preset] [--dotenv] [--envName]
|
|
14
|
+
```
|
|
15
|
+
<!--/build-cmd-->
|
|
16
|
+
|
|
17
|
+
The `build` command creates a `.output` directory with all your application, server and dependencies ready for production.
|
|
18
|
+
|
|
19
|
+
## Arguments
|
|
20
|
+
|
|
21
|
+
<!--build-args-->
|
|
22
|
+
Argument | Description
|
|
23
|
+
--- | ---
|
|
24
|
+
`ROOTDIR="."` | Specifies the working directory (default: `.`)
|
|
25
|
+
<!--/build-args-->
|
|
26
|
+
|
|
27
|
+
## Options
|
|
28
|
+
|
|
29
|
+
<!--build-opts-->
|
|
30
|
+
Option | Default | Description
|
|
31
|
+
--- | --- | ---
|
|
32
|
+
`--cwd=<directory>` | | Specify the working directory, this takes precedence over ROOTDIR (default: `.`)
|
|
33
|
+
`--logLevel=<silent\|info\|verbose>` | | Specify build-time log level
|
|
34
|
+
`--prerender` | | Build Nuxt and prerender static routes
|
|
35
|
+
`--preset` | | Nitro server preset
|
|
36
|
+
`--dotenv` | | Path to `.env` file to load, relative to the root directory
|
|
37
|
+
`--envName` | | The environment to use when resolving configuration overrides (default is `production` when building, and `development` when running the dev server)
|
|
38
|
+
<!--/build-opts-->
|
|
39
|
+
|
|
40
|
+
::note
|
|
41
|
+
This command sets `process.env.NODE_ENV` to `production`.
|
|
42
|
+
::
|
|
43
|
+
|
|
44
|
+
::note
|
|
45
|
+
`--prerender` will always set the `preset` to `static`
|
|
46
|
+
::
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: 'nuxi cleanup'
|
|
3
|
+
description: 'Remove common generated Nuxt files and caches.'
|
|
4
|
+
links:
|
|
5
|
+
- label: Source
|
|
6
|
+
icon: i-simple-icons-github
|
|
7
|
+
to: https://github.com/nuxt/cli/blob/main/packages/nuxi/src/commands/cleanup.ts
|
|
8
|
+
size: xs
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
<!--cleanup-cmd-->
|
|
12
|
+
```bash [Terminal]
|
|
13
|
+
npx nuxi cleanup [ROOTDIR] [--cwd=<directory>]
|
|
14
|
+
```
|
|
15
|
+
<!--/cleanup-cmd-->
|
|
16
|
+
|
|
17
|
+
The `cleanup` command removes common generated Nuxt files and caches, including:
|
|
18
|
+
|
|
19
|
+
- `.nuxt`
|
|
20
|
+
- `.output`
|
|
21
|
+
- `node_modules/.vite`
|
|
22
|
+
- `node_modules/.cache`
|
|
23
|
+
|
|
24
|
+
## Arguments
|
|
25
|
+
|
|
26
|
+
<!--cleanup-args-->
|
|
27
|
+
Argument | Description
|
|
28
|
+
--- | ---
|
|
29
|
+
`ROOTDIR="."` | Specifies the working directory (default: `.`)
|
|
30
|
+
<!--/cleanup-args-->
|
|
31
|
+
|
|
32
|
+
## Options
|
|
33
|
+
|
|
34
|
+
<!--cleanup-opts-->
|
|
35
|
+
Option | Default | Description
|
|
36
|
+
--- | --- | ---
|
|
37
|
+
`--cwd=<directory>` | | Specify the working directory, this takes precedence over ROOTDIR (default: `.`)
|
|
38
|
+
<!--/cleanup-opts-->
|