@nuxt/docs-nightly 4.1.3-29314777.50febbbb → 4.1.3-29316215.910d159d
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/1.getting-started/03.configuration.md +19 -19
- package/1.getting-started/04.views.md +1 -1
- package/1.getting-started/05.assets.md +8 -2
- package/1.getting-started/06.styling.md +50 -40
- package/1.getting-started/07.routing.md +4 -4
- package/1.getting-started/08.seo-meta.md +46 -33
- package/1.getting-started/09.transitions.md +38 -33
- package/1.getting-started/10.data-fetching.md +47 -39
- package/1.getting-started/11.state-management.md +15 -8
- package/1.getting-started/12.error-handling.md +6 -4
- package/1.getting-started/13.server.md +3 -3
- package/1.getting-started/14.layers.md +18 -12
- package/1.getting-started/15.prerendering.md +24 -24
- package/1.getting-started/16.deployment.md +7 -7
- package/1.getting-started/17.testing.md +41 -41
- package/1.getting-started/18.upgrade.md +48 -66
- package/2.guide/1.directory-structure/1.app/1.components.md +36 -19
- package/2.guide/1.directory-structure/1.app/1.composables.md +7 -7
- package/2.guide/1.directory-structure/1.app/1.layouts.md +9 -5
- package/2.guide/1.directory-structure/1.app/1.middleware.md +20 -14
- package/2.guide/1.directory-structure/1.app/1.pages.md +19 -17
- package/2.guide/1.directory-structure/1.app/1.plugins.md +17 -17
- package/2.guide/1.directory-structure/1.app/1.utils.md +1 -1
- package/2.guide/1.directory-structure/1.app/3.app-config.md +6 -6
- package/2.guide/1.directory-structure/1.app/3.error.md +4 -4
- package/2.guide/1.directory-structure/1.content.md +4 -1
- package/2.guide/1.directory-structure/1.modules.md +4 -4
- package/2.guide/1.directory-structure/1.public.md +1 -1
- package/2.guide/1.directory-structure/1.server.md +28 -28
- package/2.guide/1.directory-structure/1.shared.md +1 -1
- package/2.guide/2.concepts/1.auto-imports.md +11 -11
- package/2.guide/2.concepts/2.vuejs-development.md +5 -5
- package/2.guide/2.concepts/3.rendering.md +14 -12
- package/2.guide/2.concepts/5.modules.md +2 -2
- package/2.guide/2.concepts/7.esm.md +14 -12
- package/2.guide/2.concepts/8.typescript.md +4 -4
- package/2.guide/3.going-further/1.events.md +2 -2
- package/2.guide/3.going-further/1.experimental-features.md +234 -73
- package/2.guide/3.going-further/1.features.md +44 -9
- package/2.guide/3.going-further/1.internals.md +15 -15
- package/2.guide/3.going-further/10.runtime-config.md +7 -7
- package/2.guide/3.going-further/2.hooks.md +8 -8
- package/2.guide/3.going-further/3.modules.md +76 -74
- package/2.guide/3.going-further/4.kit.md +3 -3
- package/2.guide/3.going-further/6.nuxt-app.md +1 -1
- package/2.guide/3.going-further/7.layers.md +50 -41
- package/2.guide/3.going-further/9.debugging.md +2 -2
- package/2.guide/4.recipes/1.custom-routing.md +19 -19
- package/2.guide/4.recipes/2.vite-plugin.md +3 -3
- package/2.guide/4.recipes/3.custom-usefetch.md +9 -9
- package/2.guide/4.recipes/4.sessions-and-authentication.md +33 -19
- package/2.guide/5.best-practices/performance.md +8 -8
- package/3.api/1.components/1.client-only.md +6 -3
- package/3.api/1.components/1.nuxt-client-fallback.md +9 -6
- package/3.api/1.components/11.teleports.md +4 -1
- package/3.api/1.components/12.nuxt-route-announcer.md +7 -7
- package/3.api/1.components/13.nuxt-time.md +44 -17
- package/3.api/1.components/2.nuxt-page.md +2 -2
- package/3.api/1.components/3.nuxt-layout.md +9 -4
- package/3.api/1.components/4.nuxt-link.md +38 -18
- package/3.api/1.components/6.nuxt-error-boundary.md +11 -9
- package/3.api/2.composables/on-prehydrate.md +2 -2
- package/3.api/2.composables/use-async-data.md +11 -11
- package/3.api/2.composables/use-cookie.md +26 -18
- package/3.api/2.composables/use-error.md +1 -1
- package/3.api/2.composables/use-fetch.md +13 -13
- package/3.api/2.composables/use-head-safe.md +5 -5
- package/3.api/2.composables/use-head.md +2 -2
- package/3.api/2.composables/use-hydration.md +5 -5
- package/3.api/2.composables/use-loading-indicator.md +10 -10
- package/3.api/2.composables/use-nuxt-app.md +9 -9
- package/3.api/2.composables/use-nuxt-data.md +7 -7
- package/3.api/2.composables/use-preview-mode.md +12 -15
- package/3.api/2.composables/use-request-fetch.md +1 -1
- package/3.api/2.composables/use-request-headers.md +3 -3
- package/3.api/2.composables/use-response-header.md +7 -8
- package/3.api/2.composables/use-route-announcer.md +3 -3
- package/3.api/2.composables/use-router.md +5 -3
- package/3.api/2.composables/use-runtime-config.md +6 -6
- package/3.api/2.composables/use-runtime-hook.md +1 -1
- package/3.api/2.composables/use-seo-meta.md +1 -1
- package/3.api/2.composables/use-server-seo-meta.md +1 -1
- package/3.api/2.composables/use-state.md +3 -3
- package/3.api/3.utils/$fetch.md +5 -3
- package/3.api/3.utils/abort-navigation.md +2 -2
- package/3.api/3.utils/add-route-middleware.md +3 -3
- package/3.api/3.utils/call-once.md +3 -3
- package/3.api/3.utils/clear-error.md +1 -1
- package/3.api/3.utils/clear-nuxt-data.md +2 -2
- package/3.api/3.utils/clear-nuxt-state.md +2 -2
- package/3.api/3.utils/create-error.md +1 -1
- package/3.api/3.utils/define-lazy-hydration-component.md +13 -13
- package/3.api/3.utils/define-nuxt-component.md +5 -5
- package/3.api/3.utils/define-nuxt-plugin.md +11 -11
- package/3.api/3.utils/define-nuxt-route-middleware.md +2 -2
- package/3.api/3.utils/define-page-meta.md +14 -14
- package/3.api/3.utils/define-route-rules.md +3 -3
- package/3.api/3.utils/navigate-to.md +9 -9
- package/3.api/3.utils/preload-components.md +1 -1
- package/3.api/3.utils/prerender-routes.md +2 -2
- package/3.api/3.utils/refresh-cookie.md +3 -3
- package/3.api/3.utils/refresh-nuxt-data.md +9 -4
- package/3.api/3.utils/reload-nuxt-app.md +2 -2
- package/3.api/3.utils/set-response-status.md +1 -1
- package/3.api/3.utils/show-error.md +2 -2
- package/3.api/3.utils/update-app-config.md +2 -1
- package/3.api/4.commands/prepare.md +4 -0
- package/3.api/5.kit/1.modules.md +36 -36
- package/3.api/5.kit/10.templates.md +8 -6
- package/3.api/5.kit/11.nitro.md +62 -62
- package/3.api/5.kit/12.resolving.md +2 -2
- package/3.api/5.kit/14.builder.md +1 -0
- package/3.api/5.kit/15.examples.md +2 -2
- package/3.api/5.kit/16.layers.md +26 -26
- package/3.api/5.kit/3.compatibility.md +12 -12
- package/3.api/5.kit/4.autoimports.md +12 -12
- package/3.api/5.kit/5.components.md +5 -5
- package/3.api/5.kit/6.context.md +3 -3
- package/3.api/5.kit/7.pages.md +4 -4
- package/3.api/5.kit/8.layout.md +1 -1
- package/3.api/5.kit/9.plugins.md +5 -4
- package/3.api/6.advanced/2.import-meta.md +3 -3
- package/3.api/6.nuxt-config.md +293 -858
- package/6.bridge/1.overview.md +1 -1
- package/6.bridge/10.configuration.md +2 -1
- package/6.bridge/2.typescript.md +2 -2
- package/6.bridge/3.bridge-composition-api.md +2 -2
- package/6.bridge/4.plugins-and-middleware.md +5 -5
- package/6.bridge/5.nuxt3-compatible-api.md +11 -8
- package/6.bridge/6.meta.md +15 -14
- package/6.bridge/8.nitro.md +2 -2
- package/6.bridge/9.vite.md +3 -3
- package/7.migration/2.configuration.md +17 -15
- package/7.migration/4.meta.md +17 -14
- package/7.migration/5.plugins-and-middleware.md +5 -5
- package/7.migration/6.pages-and-layouts.md +15 -11
- package/7.migration/7.component-options.md +3 -3
- package/7.migration/8.runtime-config.md +3 -3
- package/package.json +1 -1
|
@@ -24,7 +24,7 @@ The handler can directly return JSON data, a `Promise`, or use `event.node.res.e
|
|
|
24
24
|
```ts twoslash [server/api/hello.ts]
|
|
25
25
|
export default defineEventHandler((event) => {
|
|
26
26
|
return {
|
|
27
|
-
hello: 'world'
|
|
27
|
+
hello: 'world',
|
|
28
28
|
}
|
|
29
29
|
})
|
|
30
30
|
```
|
|
@@ -115,9 +115,9 @@ For example, you can define a custom handler utility that wraps the original han
|
|
|
115
115
|
import type { EventHandler, EventHandlerRequest } from 'h3'
|
|
116
116
|
|
|
117
117
|
export const defineWrappedResponseHandler = <T extends EventHandlerRequest, D> (
|
|
118
|
-
handler: EventHandler<T, D
|
|
118
|
+
handler: EventHandler<T, D>,
|
|
119
119
|
): EventHandler<T, D> =>
|
|
120
|
-
defineEventHandler<T>(async event => {
|
|
120
|
+
defineEventHandler<T>(async (event) => {
|
|
121
121
|
try {
|
|
122
122
|
// do something before the route handler
|
|
123
123
|
const response = await handler(event)
|
|
@@ -234,10 +234,10 @@ You can now universally call this API using:
|
|
|
234
234
|
|
|
235
235
|
```vue [app/app.vue]
|
|
236
236
|
<script setup lang="ts">
|
|
237
|
-
async function submit() {
|
|
237
|
+
async function submit () {
|
|
238
238
|
const { body } = await $fetch('/api/submit', {
|
|
239
239
|
method: 'post',
|
|
240
|
-
body: { test: 123 }
|
|
240
|
+
body: { test: 123 },
|
|
241
241
|
})
|
|
242
242
|
}
|
|
243
243
|
</script>
|
|
@@ -273,7 +273,7 @@ To return other error codes, throw an exception with [`createError`](/docs/4.x/a
|
|
|
273
273
|
|
|
274
274
|
```ts [server/api/validation/[id\\].ts]
|
|
275
275
|
export default defineEventHandler((event) => {
|
|
276
|
-
const id = parseInt(event.context.params.id) as number
|
|
276
|
+
const id = Number.parseInt(event.context.params.id) as number
|
|
277
277
|
|
|
278
278
|
if (!Number.isInteger(id)) {
|
|
279
279
|
throw createError({
|
|
@@ -306,8 +306,8 @@ export default defineEventHandler(async (event) => {
|
|
|
306
306
|
|
|
307
307
|
const repo = await $fetch('https://api.github.com/repos/nuxt/nuxt', {
|
|
308
308
|
headers: {
|
|
309
|
-
Authorization: `token ${config.githubToken}
|
|
310
|
-
}
|
|
309
|
+
Authorization: `token ${config.githubToken}`,
|
|
310
|
+
},
|
|
311
311
|
})
|
|
312
312
|
|
|
313
313
|
return repo
|
|
@@ -316,8 +316,8 @@ export default defineEventHandler(async (event) => {
|
|
|
316
316
|
```ts [nuxt.config.ts]
|
|
317
317
|
export default defineNuxtConfig({
|
|
318
318
|
runtimeConfig: {
|
|
319
|
-
githubToken: ''
|
|
320
|
-
}
|
|
319
|
+
githubToken: '',
|
|
320
|
+
},
|
|
321
321
|
})
|
|
322
322
|
```
|
|
323
323
|
```ini [.env]
|
|
@@ -363,8 +363,8 @@ The `event.waitUntil` method accepts a promise that will be awaited before the h
|
|
|
363
363
|
|
|
364
364
|
```ts [server/api/background-task.ts]
|
|
365
365
|
const timeConsumingBackgroundTask = async () => {
|
|
366
|
-
await new Promise(
|
|
367
|
-
}
|
|
366
|
+
await new Promise(resolve => setTimeout(resolve, 1000))
|
|
367
|
+
}
|
|
368
368
|
|
|
369
369
|
export default eventHandler((event) => {
|
|
370
370
|
// schedule a background task without blocking the response
|
|
@@ -372,7 +372,7 @@ export default eventHandler((event) => {
|
|
|
372
372
|
|
|
373
373
|
// immediately send the response to the client
|
|
374
374
|
return 'done'
|
|
375
|
-
})
|
|
375
|
+
})
|
|
376
376
|
```
|
|
377
377
|
|
|
378
378
|
## Advanced Usage
|
|
@@ -388,7 +388,7 @@ This is an advanced option. Custom config can affect production deployments, as
|
|
|
388
388
|
```ts [nuxt.config.ts]
|
|
389
389
|
export default defineNuxtConfig({
|
|
390
390
|
// https://nitro.build/config
|
|
391
|
-
nitro: {}
|
|
391
|
+
nitro: {},
|
|
392
392
|
})
|
|
393
393
|
```
|
|
394
394
|
|
|
@@ -468,14 +468,14 @@ export default defineNuxtConfig({
|
|
|
468
468
|
driver: 'redis',
|
|
469
469
|
/* redis connector options */
|
|
470
470
|
port: 6379, // Redis port
|
|
471
|
-
host:
|
|
472
|
-
username:
|
|
473
|
-
password:
|
|
471
|
+
host: '127.0.0.1', // Redis host
|
|
472
|
+
username: '', // needs Redis >= 6
|
|
473
|
+
password: '',
|
|
474
474
|
db: 0, // Defaults to 0
|
|
475
|
-
tls: {} // tls/ssl
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
}
|
|
475
|
+
tls: {}, // tls/ssl
|
|
476
|
+
},
|
|
477
|
+
},
|
|
478
|
+
},
|
|
479
479
|
})
|
|
480
480
|
```
|
|
481
481
|
|
|
@@ -511,11 +511,11 @@ export default defineNitroPlugin(() => {
|
|
|
511
511
|
|
|
512
512
|
// Dynamically pass in credentials from runtime configuration, or other sources
|
|
513
513
|
const driver = redisDriver({
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
514
|
+
base: 'redis',
|
|
515
|
+
host: useRuntimeConfig().redis.host,
|
|
516
|
+
port: useRuntimeConfig().redis.port,
|
|
517
|
+
/* other redis connector options */
|
|
518
|
+
})
|
|
519
519
|
|
|
520
520
|
// Mount driver
|
|
521
521
|
storage.mount('redis', driver)
|
|
@@ -529,8 +529,8 @@ export default defineNuxtConfig({
|
|
|
529
529
|
host: '',
|
|
530
530
|
port: 0,
|
|
531
531
|
/* other redis connector options */
|
|
532
|
-
}
|
|
533
|
-
}
|
|
532
|
+
},
|
|
533
|
+
},
|
|
534
534
|
})
|
|
535
535
|
```
|
|
536
536
|
::
|
|
@@ -120,7 +120,7 @@ Nuxt exposes every auto-import with the `#imports` alias that can be used to mak
|
|
|
120
120
|
|
|
121
121
|
```vue
|
|
122
122
|
<script setup lang="ts">
|
|
123
|
-
import {
|
|
123
|
+
import { computed, ref } from '#imports'
|
|
124
124
|
|
|
125
125
|
const count = ref(1)
|
|
126
126
|
const double = computed(() => count.value * 2)
|
|
@@ -134,8 +134,8 @@ If you want to disable auto-importing composables and utilities, you can set `im
|
|
|
134
134
|
```ts twoslash [nuxt.config.ts]
|
|
135
135
|
export default defineNuxtConfig({
|
|
136
136
|
imports: {
|
|
137
|
-
autoImport: false
|
|
138
|
-
}
|
|
137
|
+
autoImport: false,
|
|
138
|
+
},
|
|
139
139
|
})
|
|
140
140
|
```
|
|
141
141
|
|
|
@@ -148,8 +148,8 @@ If you want framework-specific functions like `ref` to remain auto-imported but
|
|
|
148
148
|
```ts
|
|
149
149
|
export default defineNuxtConfig({
|
|
150
150
|
imports: {
|
|
151
|
-
scan: false
|
|
152
|
-
}
|
|
151
|
+
scan: false,
|
|
152
|
+
},
|
|
153
153
|
})
|
|
154
154
|
```
|
|
155
155
|
|
|
@@ -174,8 +174,8 @@ To disable auto-importing components from your own `~/components` directory, you
|
|
|
174
174
|
```ts twoslash [nuxt.config.ts]
|
|
175
175
|
export default defineNuxtConfig({
|
|
176
176
|
components: {
|
|
177
|
-
dirs: []
|
|
178
|
-
}
|
|
177
|
+
dirs: [],
|
|
178
|
+
},
|
|
179
179
|
})
|
|
180
180
|
```
|
|
181
181
|
|
|
@@ -195,10 +195,10 @@ export default defineNuxtConfig({
|
|
|
195
195
|
presets: [
|
|
196
196
|
{
|
|
197
197
|
from: 'vue-i18n',
|
|
198
|
-
imports: ['useI18n']
|
|
199
|
-
}
|
|
200
|
-
]
|
|
201
|
-
}
|
|
198
|
+
imports: ['useI18n'],
|
|
199
|
+
},
|
|
200
|
+
],
|
|
201
|
+
},
|
|
202
202
|
})
|
|
203
203
|
```
|
|
204
204
|
|
|
@@ -64,16 +64,16 @@ The only way to provide data and logic to components in Vue 2 was through the Op
|
|
|
64
64
|
```vue twoslash
|
|
65
65
|
<script>
|
|
66
66
|
export default {
|
|
67
|
-
data() {
|
|
67
|
+
data () {
|
|
68
68
|
return {
|
|
69
|
-
count: 0
|
|
69
|
+
count: 0,
|
|
70
70
|
}
|
|
71
71
|
},
|
|
72
72
|
methods: {
|
|
73
|
-
increment(){
|
|
73
|
+
increment () {
|
|
74
74
|
this.count++
|
|
75
|
-
}
|
|
76
|
-
}
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
77
|
}
|
|
78
78
|
</script>
|
|
79
79
|
```
|
|
@@ -25,17 +25,19 @@ It is normal to ask which parts of a Vue file runs on the server and/or the clie
|
|
|
25
25
|
|
|
26
26
|
```vue [app/app.vue]
|
|
27
27
|
<script setup lang="ts">
|
|
28
|
-
const counter = ref(0)
|
|
28
|
+
const counter = ref(0) // executes in server and client environments
|
|
29
29
|
|
|
30
30
|
const handleClick = () => {
|
|
31
|
-
counter.value
|
|
32
|
-
}
|
|
31
|
+
counter.value++ // executes only in a client environment
|
|
32
|
+
}
|
|
33
33
|
</script>
|
|
34
34
|
|
|
35
35
|
<template>
|
|
36
36
|
<div>
|
|
37
37
|
<p>Count: {{ counter }}</p>
|
|
38
|
-
<button @click="handleClick">
|
|
38
|
+
<button @click="handleClick">
|
|
39
|
+
Increment
|
|
40
|
+
</button>
|
|
39
41
|
</div>
|
|
40
42
|
</template>
|
|
41
43
|
```
|
|
@@ -83,7 +85,7 @@ You can enable client-side only rendering with Nuxt in your `nuxt.config.ts`:
|
|
|
83
85
|
|
|
84
86
|
```ts [nuxt.config.ts]
|
|
85
87
|
export default defineNuxtConfig({
|
|
86
|
-
ssr: false
|
|
88
|
+
ssr: false,
|
|
87
89
|
})
|
|
88
90
|
```
|
|
89
91
|
|
|
@@ -111,7 +113,7 @@ export default defineNuxtConfig({
|
|
|
111
113
|
hooks: {
|
|
112
114
|
'prerender:routes' ({ routes }) {
|
|
113
115
|
routes.clear() // Do not generate any routes (except the defaults)
|
|
114
|
-
}
|
|
116
|
+
},
|
|
115
117
|
},
|
|
116
118
|
})
|
|
117
119
|
```
|
|
@@ -133,14 +135,14 @@ export default defineNuxtConfig({
|
|
|
133
135
|
ssr: false,
|
|
134
136
|
nitro: {
|
|
135
137
|
hooks: {
|
|
136
|
-
'prerender:generate'(route) {
|
|
138
|
+
'prerender:generate' (route) {
|
|
137
139
|
const routesToSkip = ['/index.html', '/200.html', '/404.html']
|
|
138
140
|
if (routesToSkip.includes(route.route)) {
|
|
139
141
|
route.skip = true
|
|
140
142
|
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
}
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
},
|
|
144
146
|
})
|
|
145
147
|
```
|
|
146
148
|
|
|
@@ -172,8 +174,8 @@ export default defineNuxtConfig({
|
|
|
172
174
|
// Add cors headers on API routes
|
|
173
175
|
'/api/**': { cors: true },
|
|
174
176
|
// Redirects legacy urls
|
|
175
|
-
'/old-page': { redirect: '/new-page' }
|
|
176
|
-
}
|
|
177
|
+
'/old-page': { redirect: '/new-page' },
|
|
178
|
+
},
|
|
177
179
|
})
|
|
178
180
|
```
|
|
179
181
|
|
|
@@ -120,8 +120,8 @@ In the meantime, you can tell Nuxt not to try to import these libraries by addin
|
|
|
120
120
|
```ts twoslash
|
|
121
121
|
export default defineNuxtConfig({
|
|
122
122
|
build: {
|
|
123
|
-
transpile: ['sample-library']
|
|
124
|
-
}
|
|
123
|
+
transpile: ['sample-library'],
|
|
124
|
+
},
|
|
125
125
|
})
|
|
126
126
|
```
|
|
127
127
|
|
|
@@ -134,8 +134,8 @@ In some cases, you may also need to manually alias the library to the CJS versio
|
|
|
134
134
|
```ts twoslash
|
|
135
135
|
export default defineNuxtConfig({
|
|
136
136
|
alias: {
|
|
137
|
-
'sample-library': 'sample-library/dist/sample-library.cjs.js'
|
|
138
|
-
}
|
|
137
|
+
'sample-library': 'sample-library/dist/sample-library.cjs.js',
|
|
138
|
+
},
|
|
139
139
|
})
|
|
140
140
|
```
|
|
141
141
|
|
|
@@ -182,6 +182,8 @@ import('cjs-pkg').then(console.log) // [Module: null prototype] { default: { tes
|
|
|
182
182
|
|
|
183
183
|
In this case, we need to manually interop the default export:
|
|
184
184
|
|
|
185
|
+
<!-- eslint-disable import/no-named-default -->
|
|
186
|
+
|
|
185
187
|
```js
|
|
186
188
|
// Static import
|
|
187
189
|
import { default as pkg } from 'cjs-pkg'
|
|
@@ -219,16 +221,16 @@ The initial step from CJS to ESM is updating any usage of `require` to use `impo
|
|
|
219
221
|
|
|
220
222
|
::code-group
|
|
221
223
|
|
|
222
|
-
```
|
|
223
|
-
module.exports = ...
|
|
224
|
+
```ts [Before]
|
|
225
|
+
module.exports = function () { /* ... */ }
|
|
224
226
|
|
|
225
|
-
exports.hello =
|
|
227
|
+
exports.hello = 'world'
|
|
226
228
|
```
|
|
227
229
|
|
|
228
|
-
```
|
|
229
|
-
export default ...
|
|
230
|
+
```ts [After]
|
|
231
|
+
export default function () { /* ... */ }
|
|
230
232
|
|
|
231
|
-
export const hello =
|
|
233
|
+
export const hello = 'world'
|
|
232
234
|
```
|
|
233
235
|
|
|
234
236
|
::
|
|
@@ -242,7 +244,7 @@ const myLib = require('my-lib')
|
|
|
242
244
|
```js [After]
|
|
243
245
|
import myLib from 'my-lib'
|
|
244
246
|
// or
|
|
245
|
-
const
|
|
247
|
+
const dynamicMyLib = await import('my-lib').then(lib => lib.default || lib)
|
|
246
248
|
```
|
|
247
249
|
|
|
248
250
|
::
|
|
@@ -253,7 +255,7 @@ and should be replaced with `import()` and `import.meta.filename`.
|
|
|
253
255
|
::code-group
|
|
254
256
|
|
|
255
257
|
```js [Before]
|
|
256
|
-
|
|
258
|
+
const { join } = require('node:path')
|
|
257
259
|
|
|
258
260
|
const newDir = join(__dirname, 'new-dir')
|
|
259
261
|
```
|
|
@@ -40,8 +40,8 @@ To enable type-checking at build or development time, you can also use the [`typ
|
|
|
40
40
|
```ts twoslash [nuxt.config.ts]
|
|
41
41
|
export default defineNuxtConfig({
|
|
42
42
|
typescript: {
|
|
43
|
-
typeCheck: true
|
|
44
|
-
}
|
|
43
|
+
typeCheck: true,
|
|
44
|
+
},
|
|
45
45
|
})
|
|
46
46
|
```
|
|
47
47
|
|
|
@@ -133,7 +133,7 @@ If you are currently converting your codebase to TypeScript, you may want to tem
|
|
|
133
133
|
```ts twoslash [nuxt.config.ts]
|
|
134
134
|
export default defineNuxtConfig({
|
|
135
135
|
typescript: {
|
|
136
|
-
strict: false
|
|
137
|
-
}
|
|
136
|
+
strict: false,
|
|
137
|
+
},
|
|
138
138
|
})
|
|
139
139
|
```
|
|
@@ -16,7 +16,7 @@ You can create your own custom events using the `hook` method:
|
|
|
16
16
|
```ts
|
|
17
17
|
const nuxtApp = useNuxtApp()
|
|
18
18
|
|
|
19
|
-
nuxtApp.hook('app:user:registered', payload => {
|
|
19
|
+
nuxtApp.hook('app:user:registered', (payload) => {
|
|
20
20
|
console.log('A new user has registered!', payload)
|
|
21
21
|
})
|
|
22
22
|
```
|
|
@@ -37,7 +37,7 @@ You can also use the payload object to enable two-way communication between the
|
|
|
37
37
|
```ts
|
|
38
38
|
const nuxtApp = useNuxtApp()
|
|
39
39
|
|
|
40
|
-
nuxtApp.hook('app:user:registered', payload => {
|
|
40
|
+
nuxtApp.hook('app:user:registered', (payload) => {
|
|
41
41
|
payload.message = 'Welcome to our app!'
|
|
42
42
|
})
|
|
43
43
|
|