@nuxt/docs 3.19.2 → 3.19.3
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/01.introduction.md +2 -2
- package/1.getting-started/02.installation.md +1 -0
- package/1.getting-started/03.configuration.md +29 -29
- package/1.getting-started/04.views.md +7 -7
- package/1.getting-started/05.assets.md +15 -9
- package/1.getting-started/06.styling.md +55 -45
- package/1.getting-started/07.routing.md +12 -12
- package/1.getting-started/08.seo-meta.md +55 -42
- package/1.getting-started/09.transitions.md +47 -42
- package/1.getting-started/10.data-fetching.md +90 -67
- package/1.getting-started/11.state-management.md +22 -15
- package/1.getting-started/12.error-handling.md +11 -9
- package/1.getting-started/13.server.md +3 -3
- package/1.getting-started/14.layers.md +21 -15
- package/1.getting-started/15.prerendering.md +28 -28
- package/1.getting-started/16.deployment.md +9 -9
- package/1.getting-started/17.testing.md +43 -43
- package/1.getting-started/18.upgrade.md +58 -57
- package/2.guide/0.index.md +3 -3
- package/2.guide/{2.directory-structure → 1.directory-structure}/.navigation.yml +1 -1
- package/2.guide/{2.directory-structure → 1.directory-structure}/0.nuxt.md +3 -3
- package/2.guide/{2.directory-structure → 1.directory-structure}/0.output.md +3 -3
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.assets.md +3 -3
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.components.md +41 -24
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.composables.md +11 -11
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.content.md +7 -4
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.layouts.md +16 -12
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.middleware.md +28 -22
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.modules.md +6 -6
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.node_modules.md +2 -2
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.pages.md +33 -31
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.plugins.md +25 -25
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.public.md +2 -2
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.server.md +34 -34
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.shared.md +6 -6
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.utils.md +5 -5
- package/2.guide/{2.directory-structure → 1.directory-structure}/2.env.md +5 -5
- package/2.guide/{2.directory-structure → 1.directory-structure}/2.gitignore.md +1 -1
- package/2.guide/{2.directory-structure → 1.directory-structure}/2.nuxtignore.md +4 -4
- package/2.guide/{2.directory-structure → 1.directory-structure}/2.nuxtrc.md +3 -3
- package/2.guide/{2.directory-structure → 1.directory-structure}/3.app-config.md +12 -12
- package/2.guide/{2.directory-structure → 1.directory-structure}/3.app.md +4 -4
- package/2.guide/{2.directory-structure → 1.directory-structure}/3.error.md +6 -6
- package/2.guide/{2.directory-structure → 1.directory-structure}/3.nuxt-config.md +2 -2
- package/2.guide/{2.directory-structure → 1.directory-structure}/3.package.md +1 -1
- package/2.guide/{2.directory-structure → 1.directory-structure}/3.tsconfig.md +3 -3
- package/2.guide/{1.concepts → 2.concepts}/1.auto-imports.md +18 -18
- package/2.guide/{1.concepts → 2.concepts}/10.nuxt-lifecycle.md +10 -10
- package/2.guide/{1.concepts → 2.concepts}/2.vuejs-development.md +9 -9
- package/2.guide/{1.concepts → 2.concepts}/3.rendering.md +21 -19
- package/2.guide/{1.concepts → 2.concepts}/4.server-engine.md +5 -5
- package/2.guide/{1.concepts → 2.concepts}/5.modules.md +4 -4
- package/2.guide/{1.concepts → 2.concepts}/7.esm.md +15 -13
- package/2.guide/{1.concepts → 2.concepts}/8.typescript.md +11 -11
- package/2.guide/3.going-further/1.events.md +2 -2
- package/2.guide/3.going-further/1.experimental-features.md +80 -80
- package/2.guide/3.going-further/1.features.md +15 -15
- package/2.guide/3.going-further/1.internals.md +25 -25
- package/2.guide/3.going-further/10.runtime-config.md +11 -11
- package/2.guide/3.going-further/2.hooks.md +11 -11
- package/2.guide/3.going-further/3.modules.md +89 -87
- package/2.guide/3.going-further/4.kit.md +5 -5
- package/2.guide/3.going-further/6.nuxt-app.md +5 -5
- package/2.guide/3.going-further/7.layers.md +61 -52
- package/2.guide/3.going-further/9.debugging.md +2 -2
- package/2.guide/4.recipes/1.custom-routing.md +31 -31
- package/2.guide/4.recipes/2.vite-plugin.md +4 -4
- package/2.guide/4.recipes/3.custom-usefetch.md +12 -12
- package/2.guide/4.recipes/4.sessions-and-authentication.md +34 -20
- package/2.guide/5.best-practices/hydration.md +4 -4
- package/2.guide/5.best-practices/performance.md +12 -12
- 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/10.nuxt-picture.md +1 -1
- package/3.api/1.components/11.teleports.md +4 -1
- package/3.api/1.components/12.nuxt-route-announcer.md +9 -9
- package/3.api/1.components/13.nuxt-time.md +44 -17
- package/3.api/1.components/2.nuxt-page.md +4 -4
- package/3.api/1.components/3.nuxt-layout.md +11 -6
- package/3.api/1.components/4.nuxt-link.md +40 -20
- package/3.api/1.components/5.nuxt-loading-indicator.md +2 -2
- 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 +17 -17
- package/3.api/2.composables/use-cookie.md +28 -20
- package/3.api/2.composables/use-error.md +1 -1
- package/3.api/2.composables/use-fetch.md +55 -29
- package/3.api/2.composables/use-head-safe.md +7 -7
- package/3.api/2.composables/use-head.md +4 -4
- package/3.api/2.composables/use-hydration.md +6 -6
- package/3.api/2.composables/use-lazy-async-data.md +2 -2
- package/3.api/2.composables/use-lazy-fetch.md +2 -2
- package/3.api/2.composables/use-loading-indicator.md +12 -12
- package/3.api/2.composables/use-nuxt-app.md +19 -19
- package/3.api/2.composables/use-nuxt-data.md +8 -8
- package/3.api/2.composables/use-preview-mode.md +15 -18
- package/3.api/2.composables/use-request-event.md +1 -1
- package/3.api/2.composables/use-request-fetch.md +3 -3
- package/3.api/2.composables/use-request-header.md +1 -1
- package/3.api/2.composables/use-request-headers.md +4 -4
- package/3.api/2.composables/use-request-url.md +1 -1
- package/3.api/2.composables/use-response-header.md +9 -10
- package/3.api/2.composables/use-route-announcer.md +4 -4
- package/3.api/2.composables/use-route.md +1 -1
- package/3.api/2.composables/use-router.md +9 -7
- package/3.api/2.composables/use-runtime-config.md +6 -6
- package/3.api/2.composables/use-runtime-hook.md +2 -2
- package/3.api/2.composables/use-seo-meta.md +2 -2
- package/3.api/2.composables/use-server-seo-meta.md +4 -4
- package/3.api/2.composables/use-state.md +4 -4
- package/3.api/3.utils/$fetch.md +9 -7
- package/3.api/3.utils/abort-navigation.md +3 -3
- package/3.api/3.utils/add-route-middleware.md +5 -5
- package/3.api/3.utils/call-once.md +4 -4
- package/3.api/3.utils/clear-error.md +2 -2
- package/3.api/3.utils/clear-nuxt-data.md +3 -3
- package/3.api/3.utils/clear-nuxt-state.md +3 -3
- 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 +12 -12
- package/3.api/3.utils/define-nuxt-route-middleware.md +5 -5
- package/3.api/3.utils/define-page-meta.md +21 -21
- package/3.api/3.utils/define-route-rules.md +5 -5
- package/3.api/3.utils/navigate-to.md +10 -10
- package/3.api/3.utils/prefetch-components.md +1 -1
- package/3.api/3.utils/preload-components.md +1 -1
- package/3.api/3.utils/prerender-routes.md +3 -3
- package/3.api/3.utils/refresh-cookie.md +3 -3
- package/3.api/3.utils/refresh-nuxt-data.md +11 -6
- package/3.api/3.utils/reload-nuxt-app.md +2 -2
- package/3.api/3.utils/set-page-layout.md +1 -1
- package/3.api/3.utils/set-response-status.md +2 -2
- package/3.api/3.utils/show-error.md +4 -4
- package/3.api/3.utils/update-app-config.md +3 -2
- package/3.api/4.commands/add.md +1 -1
- package/3.api/4.commands/analyze.md +2 -1
- package/3.api/4.commands/build.md +2 -1
- package/3.api/4.commands/dev.md +5 -4
- package/3.api/4.commands/generate.md +2 -1
- package/3.api/4.commands/init.md +3 -2
- package/3.api/4.commands/module.md +4 -4
- package/3.api/4.commands/prepare.md +7 -2
- package/3.api/4.commands/preview.md +5 -4
- package/3.api/4.commands/test.md +40 -0
- package/3.api/4.commands/typecheck.md +4 -2
- package/3.api/4.commands/upgrade.md +3 -3
- package/3.api/5.kit/1.modules.md +36 -36
- package/3.api/5.kit/10.runtime-config.md +1 -1
- 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 +13 -13
- package/3.api/5.kit/5.components.md +7 -7
- package/3.api/5.kit/6.context.md +3 -3
- package/3.api/5.kit/7.pages.md +7 -7
- package/3.api/5.kit/8.layout.md +2 -2
- package/3.api/5.kit/9.plugins.md +6 -5
- package/3.api/6.advanced/1.hooks.md +2 -2
- package/3.api/6.advanced/2.import-meta.md +3 -3
- package/5.community/2.getting-help.md +1 -1
- package/5.community/3.reporting-bugs.md +1 -1
- package/5.community/4.contribution.md +6 -6
- package/5.community/5.framework-contribution.md +3 -3
- package/5.community/6.roadmap.md +1 -1
- package/6.bridge/1.overview.md +13 -13
- package/6.bridge/10.configuration.md +2 -1
- package/6.bridge/2.typescript.md +2 -2
- package/6.bridge/3.bridge-composition-api.md +6 -6
- package/6.bridge/4.plugins-and-middleware.md +9 -9
- package/6.bridge/5.nuxt3-compatible-api.md +19 -16
- package/6.bridge/6.meta.md +20 -19
- package/6.bridge/7.runtime-config.md +1 -1
- package/6.bridge/8.nitro.md +3 -3
- package/6.bridge/9.vite.md +4 -4
- package/7.migration/1.overview.md +2 -2
- package/7.migration/2.configuration.md +22 -20
- package/7.migration/20.module-authors.md +6 -6
- package/7.migration/3.auto-imports.md +3 -3
- package/7.migration/4.meta.md +20 -17
- package/7.migration/5.plugins-and-middleware.md +5 -5
- package/7.migration/6.pages-and-layouts.md +23 -19
- package/7.migration/7.component-options.md +14 -14
- package/7.migration/8.runtime-config.md +6 -6
- package/package.json +1 -1
- /package/2.guide/{1.concepts → 2.concepts}/.navigation.yml +0 -0
- /package/2.guide/{1.concepts → 2.concepts}/9.code-style.md +0 -0
|
@@ -19,13 +19,13 @@ This file is a great place to put any custom code that needs to be run once when
|
|
|
19
19
|
|
|
20
20
|
### Migration
|
|
21
21
|
|
|
22
|
-
Consider creating an `app.vue` file and including any logic that needs to run once at the top-level of your app. You can check out [an example here](/docs/guide/directory-structure/app).
|
|
22
|
+
Consider creating an `app.vue` file and including any logic that needs to run once at the top-level of your app. You can check out [an example here](/docs/3.x/guide/directory-structure/app).
|
|
23
23
|
|
|
24
24
|
## Layouts
|
|
25
25
|
|
|
26
26
|
If you are using layouts in your app for multiple pages, there is only a slight change required.
|
|
27
27
|
|
|
28
|
-
In Nuxt 2, the `<Nuxt>` component is used within a layout to render the current page. In Nuxt 3, layouts use slots instead, so you will have to replace that component with a `<slot />`. This also allows advanced use cases with named and scoped slots. [Read more about layouts](/docs/guide/directory-structure/layouts).
|
|
28
|
+
In Nuxt 2, the `<Nuxt>` component is used within a layout to render the current page. In Nuxt 3, layouts use slots instead, so you will have to replace that component with a `<slot />`. This also allows advanced use cases with named and scoped slots. [Read more about layouts](/docs/3.x/guide/directory-structure/layouts).
|
|
29
29
|
|
|
30
30
|
You will also need to change how you define the layout used by a page using the `definePageMeta` compiler macro. Layouts will be kebab-cased. So `layouts/customLayout.vue` becomes `custom-layout` when referenced in your page.
|
|
31
31
|
|
|
@@ -42,7 +42,7 @@ You will also need to change how you define the layout used by a page using the
|
|
|
42
42
|
</div>
|
|
43
43
|
</template>
|
|
44
44
|
```
|
|
45
|
-
2. Use [`definePageMeta`](/docs/api/utils/define-page-meta) to select the layout used by your page.
|
|
45
|
+
2. Use [`definePageMeta`](/docs/3.x/api/utils/define-page-meta) to select the layout used by your page.
|
|
46
46
|
```diff [pages/index.vue]
|
|
47
47
|
+ <script setup>
|
|
48
48
|
+ definePageMeta({
|
|
@@ -54,7 +54,7 @@ You will also need to change how you define the layout used by a page using the
|
|
|
54
54
|
- }
|
|
55
55
|
</script>
|
|
56
56
|
```
|
|
57
|
-
3. Move `~/layouts/_error.vue` to `~/error.vue`. See [the error handling docs](/docs/getting-started/error-handling). If you want to ensure that this page uses a layout, you can use [`<NuxtLayout>`](/docs/guide/directory-structure/layouts) directly within `error.vue`:
|
|
57
|
+
3. Move `~/layouts/_error.vue` to `~/error.vue`. See [the error handling docs](/docs/3.x/getting-started/error-handling). If you want to ensure that this page uses a layout, you can use [`<NuxtLayout>`](/docs/3.x/guide/directory-structure/layouts) directly within `error.vue`:
|
|
58
58
|
```vue [error.vue]
|
|
59
59
|
<template>
|
|
60
60
|
<div>
|
|
@@ -67,7 +67,7 @@ You will also need to change how you define the layout used by a page using the
|
|
|
67
67
|
|
|
68
68
|
## Pages
|
|
69
69
|
|
|
70
|
-
Nuxt 3 ships with an optional `vue-router` integration triggered by the existence of a [`pages/`](/docs/guide/directory-structure/pages) directory in your source directory. If you only have a single page, you may consider instead moving it to `app.vue` for a lighter build.
|
|
70
|
+
Nuxt 3 ships with an optional `vue-router` integration triggered by the existence of a [`pages/`](/docs/3.x/guide/directory-structure/pages) directory in your source directory. If you only have a single page, you may consider instead moving it to `app.vue` for a lighter build.
|
|
71
71
|
|
|
72
72
|
### Dynamic Routes
|
|
73
73
|
|
|
@@ -96,7 +96,7 @@ If you have been defining transitions for your page or layout directly in your c
|
|
|
96
96
|
|
|
97
97
|
1. Rename any pages with dynamic parameters to match the new format.
|
|
98
98
|
2. Update `<Nuxt>` and `<NuxtChild>` to be `<NuxtPage>`.
|
|
99
|
-
3. If you're using the Composition API, you can also migrate `this.$route` and `this.$router` to use [`useRoute`](/docs/api/composables/use-route) and [`useRouter`](/docs/api/composables/use-router) composables.
|
|
99
|
+
3. If you're using the Composition API, you can also migrate `this.$route` and `this.$router` to use [`useRoute`](/docs/3.x/api/composables/use-route) and [`useRouter`](/docs/3.x/api/composables/use-router) composables.
|
|
100
100
|
|
|
101
101
|
#### Example: Dynamic Routes
|
|
102
102
|
|
|
@@ -145,13 +145,17 @@ If you have been defining transitions for your page or layout directly in your c
|
|
|
145
145
|
```vue [Nuxt 2]
|
|
146
146
|
<template>
|
|
147
147
|
<div>
|
|
148
|
-
<NuxtChild
|
|
148
|
+
<NuxtChild
|
|
149
|
+
keep-alive
|
|
150
|
+
:keep-alive-props="{ exclude: ['modal'] }"
|
|
151
|
+
:nuxt-child-key="$route.slug"
|
|
152
|
+
/>
|
|
149
153
|
</div>
|
|
150
154
|
</template>
|
|
151
155
|
|
|
152
156
|
<script>
|
|
153
157
|
export default {
|
|
154
|
-
transition: 'page' // or { name: 'page' }
|
|
158
|
+
transition: 'page', // or { name: 'page' }
|
|
155
159
|
}
|
|
156
160
|
</script>
|
|
157
161
|
```
|
|
@@ -172,7 +176,7 @@ definePageMeta({
|
|
|
172
176
|
name: 'page',
|
|
173
177
|
},
|
|
174
178
|
keepalive: {
|
|
175
|
-
exclude: ['modal']
|
|
179
|
+
exclude: ['modal'],
|
|
176
180
|
},
|
|
177
181
|
})
|
|
178
182
|
</script>
|
|
@@ -182,7 +186,7 @@ definePageMeta({
|
|
|
182
186
|
|
|
183
187
|
## `<NuxtLink>` Component
|
|
184
188
|
|
|
185
|
-
Most of the syntax and functionality are the same for the global [NuxtLink](/docs/api/components/nuxt-link) component. If you have been using the shortcut `<NLink>` format, you should update this to use `<NuxtLink>`.
|
|
189
|
+
Most of the syntax and functionality are the same for the global [NuxtLink](/docs/3.x/api/components/nuxt-link) component. If you have been using the shortcut `<NLink>` format, you should update this to use `<NuxtLink>`.
|
|
186
190
|
|
|
187
191
|
`<NuxtLink>` is now a drop-in replacement for _all_ links, even external ones. You can read more about it, and how to extend it to provide your own link component.
|
|
188
192
|
|
|
@@ -193,7 +197,7 @@ Most of the syntax and functionality are the same for the global [NuxtLink](/doc
|
|
|
193
197
|
When migrating from Nuxt 2 to Nuxt 3, you will have to update how you programmatically navigate your users. In Nuxt 2, you had access to the underlying Vue Router with `this.$router`. In Nuxt 3, you can use the `navigateTo()` utility method which allows you to pass a route and parameters to Vue Router.
|
|
194
198
|
|
|
195
199
|
::warning
|
|
196
|
-
Make sure to always `await` on [`navigateTo`](/docs/api/utils/navigate-to) or chain its result by returning from functions.
|
|
200
|
+
Make sure to always `await` on [`navigateTo`](/docs/3.x/api/utils/navigate-to) or chain its result by returning from functions.
|
|
197
201
|
::
|
|
198
202
|
|
|
199
203
|
::code-group
|
|
@@ -202,29 +206,29 @@ Make sure to always `await` on [`navigateTo`](/docs/api/utils/navigate-to) or ch
|
|
|
202
206
|
<script>
|
|
203
207
|
export default {
|
|
204
208
|
methods: {
|
|
205
|
-
navigate(){
|
|
209
|
+
navigate () {
|
|
206
210
|
this.$router.push({
|
|
207
211
|
path: '/search',
|
|
208
212
|
query: {
|
|
209
213
|
name: 'first name',
|
|
210
|
-
type: '1'
|
|
211
|
-
}
|
|
214
|
+
type: '1',
|
|
215
|
+
},
|
|
212
216
|
})
|
|
213
|
-
}
|
|
214
|
-
}
|
|
217
|
+
},
|
|
218
|
+
},
|
|
215
219
|
}
|
|
216
220
|
</script>
|
|
217
221
|
```
|
|
218
222
|
|
|
219
223
|
```vue [Nuxt 3]
|
|
220
224
|
<script setup lang="ts">
|
|
221
|
-
function navigate(){
|
|
225
|
+
function navigate () {
|
|
222
226
|
return navigateTo({
|
|
223
227
|
path: '/search',
|
|
224
228
|
query: {
|
|
225
229
|
name: 'first name',
|
|
226
|
-
type: '1'
|
|
227
|
-
}
|
|
230
|
+
type: '1',
|
|
231
|
+
},
|
|
228
232
|
})
|
|
229
233
|
}
|
|
230
234
|
</script>
|
|
@@ -5,7 +5,7 @@ description: 'Learn how to migrate from Nuxt 2 components options to Nuxt 3 comp
|
|
|
5
5
|
|
|
6
6
|
## `asyncData` and `fetch`
|
|
7
7
|
|
|
8
|
-
Nuxt 3 provides new options for [fetching data from an API](/docs/getting-started/data-fetching).
|
|
8
|
+
Nuxt 3 provides new options for [fetching data from an API](/docs/3.x/getting-started/data-fetching).
|
|
9
9
|
|
|
10
10
|
<!-- TODO: Intro to <script setup> -->
|
|
11
11
|
<!-- TODO: Mention about options compatibility with asyncData -->
|
|
@@ -14,30 +14,30 @@ Nuxt 3 provides new options for [fetching data from an API](/docs/getting-starte
|
|
|
14
14
|
|
|
15
15
|
In Nuxt 2 you might use `@nuxtjs/axios` or `@nuxt/http` to fetch your data - or just the polyfilled global `fetch`.
|
|
16
16
|
|
|
17
|
-
In Nuxt 3 you can use a globally available `fetch` method that has the same API as [the Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch) or [`$fetch`](/docs/api/utils/dollarfetch) method which is using [unjs/ofetch](https://github.com/unjs/ofetch). It has a number of benefits, including:
|
|
17
|
+
In Nuxt 3 you can use a globally available `fetch` method that has the same API as [the Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch) or [`$fetch`](/docs/3.x/api/utils/dollarfetch) method which is using [unjs/ofetch](https://github.com/unjs/ofetch). It has a number of benefits, including:
|
|
18
18
|
|
|
19
|
-
1. It will handle 'smartly' making [direct API calls](/docs/guide/concepts/server-engine#direct-api-calls) if it's running on the server, or making a client-side call to your API if it's running on the client. (It can also handle calling third-party APIs.)
|
|
19
|
+
1. It will handle 'smartly' making [direct API calls](/docs/3.x/guide/concepts/server-engine#direct-api-calls) if it's running on the server, or making a client-side call to your API if it's running on the client. (It can also handle calling third-party APIs.)
|
|
20
20
|
|
|
21
21
|
2. Plus, it comes with convenience features including automatically parsing responses and stringifying data.
|
|
22
22
|
|
|
23
|
-
You can read more [about direct API calls](/docs/guide/concepts/server-engine#direct-api-calls) or [fetching data](/docs/getting-started/data-fetching).
|
|
23
|
+
You can read more [about direct API calls](/docs/3.x/guide/concepts/server-engine#direct-api-calls) or [fetching data](/docs/3.x/getting-started/data-fetching).
|
|
24
24
|
|
|
25
25
|
### Composables
|
|
26
26
|
|
|
27
|
-
Nuxt 3 provides new composables for fetching data: [`useAsyncData`](/docs/api/composables/use-async-data) and `useFetch`. They each have 'lazy' variants (`useLazyAsyncData` and `useLazyFetch`), which do not block client-side navigation.
|
|
27
|
+
Nuxt 3 provides new composables for fetching data: [`useAsyncData`](/docs/3.x/api/composables/use-async-data) and `useFetch`. They each have 'lazy' variants (`useLazyAsyncData` and `useLazyFetch`), which do not block client-side navigation.
|
|
28
28
|
|
|
29
29
|
In Nuxt 2, you'd fetch your data in your component using a syntax similar to:
|
|
30
30
|
|
|
31
31
|
```ts
|
|
32
32
|
export default {
|
|
33
|
-
async asyncData({ params, $http }) {
|
|
33
|
+
async asyncData ({ params, $http }) {
|
|
34
34
|
const post = await $http.$get(`https://api.nuxtjs.dev/posts/${params.id}`)
|
|
35
35
|
return { post }
|
|
36
36
|
},
|
|
37
37
|
// or alternatively
|
|
38
38
|
fetch () {
|
|
39
39
|
this.post = await $http.$get(`https://api.nuxtjs.dev/posts/${params.id}`)
|
|
40
|
-
}
|
|
40
|
+
},
|
|
41
41
|
}
|
|
42
42
|
```
|
|
43
43
|
|
|
@@ -48,7 +48,7 @@ With Nuxt 3, you can perform this data fetching using composables in your `setup
|
|
|
48
48
|
```vue
|
|
49
49
|
<script setup lang="ts">
|
|
50
50
|
// Define params wherever, through `defineProps()`, `useRoute()`, etc.
|
|
51
|
-
const { data: post, refresh } = await useAsyncData('post', () => $fetch(`https://api.nuxtjs.dev/posts/${params.id}`)
|
|
51
|
+
const { data: post, refresh } = await useAsyncData('post', () => $fetch(`https://api.nuxtjs.dev/posts/${params.id}`))
|
|
52
52
|
// Or instead - useFetch is a convenience wrapper around useAsyncData when you're just performing a simple fetch
|
|
53
53
|
const { data: post, refresh } = await useFetch(`https://api.nuxtjs.dev/posts/${params.id}`)
|
|
54
54
|
</script>
|
|
@@ -57,13 +57,13 @@ const { data: post, refresh } = await useFetch(`https://api.nuxtjs.dev/posts/${p
|
|
|
57
57
|
You can now use `post` inside of your Nuxt 3 template, or call `refresh` to update the data.
|
|
58
58
|
|
|
59
59
|
::note
|
|
60
|
-
Despite the names, [`useFetch`](/docs/api/composables/use-fetch) is not a direct replacement of the `fetch()` hook. Rather, [`useAsyncData`](/docs/api/composables/use-async-data) replaces both hooks and is more customizable; it can do more than simply fetching data from an endpoint. [`useFetch`](/docs/api/composables/use-fetch) is a convenience wrapper around [`useAsyncData`](/docs/api/composables/use-async-data) for simply fetching data from an endpoint.
|
|
60
|
+
Despite the names, [`useFetch`](/docs/3.x/api/composables/use-fetch) is not a direct replacement of the `fetch()` hook. Rather, [`useAsyncData`](/docs/3.x/api/composables/use-async-data) replaces both hooks and is more customizable; it can do more than simply fetching data from an endpoint. [`useFetch`](/docs/3.x/api/composables/use-fetch) is a convenience wrapper around [`useAsyncData`](/docs/3.x/api/composables/use-async-data) for simply fetching data from an endpoint.
|
|
61
61
|
::
|
|
62
62
|
|
|
63
63
|
### Migration
|
|
64
64
|
|
|
65
|
-
1. Replace the `asyncData` hook with [`useAsyncData`](/docs/api/composables/use-async-data) or [`useFetch`](/docs/api/composables/use-fetch) in your page/component.
|
|
66
|
-
2. Replace the `fetch` hook with [`useAsyncData`](/docs/api/composables/use-async-data) or [`useFetch`](/docs/api/composables/use-fetch) in your component.
|
|
65
|
+
1. Replace the `asyncData` hook with [`useAsyncData`](/docs/3.x/api/composables/use-async-data) or [`useFetch`](/docs/3.x/api/composables/use-fetch) in your page/component.
|
|
66
|
+
2. Replace the `fetch` hook with [`useAsyncData`](/docs/3.x/api/composables/use-async-data) or [`useFetch`](/docs/3.x/api/composables/use-fetch) in your component.
|
|
67
67
|
|
|
68
68
|
## `head`
|
|
69
69
|
|
|
@@ -71,7 +71,7 @@ Despite the names, [`useFetch`](/docs/api/composables/use-fetch) is not a direct
|
|
|
71
71
|
|
|
72
72
|
## `key`
|
|
73
73
|
|
|
74
|
-
You can now define a key within the [`definePageMeta`](/docs/api/utils/define-page-meta) compiler macro.
|
|
74
|
+
You can now define a key within the [`definePageMeta`](/docs/3.x/api/utils/define-page-meta) compiler macro.
|
|
75
75
|
|
|
76
76
|
```diff [pages/index.vue]
|
|
77
77
|
- <script>
|
|
@@ -103,8 +103,8 @@ This feature is not yet supported in Nuxt 3.
|
|
|
103
103
|
|
|
104
104
|
## `scrollToTop`
|
|
105
105
|
|
|
106
|
-
This feature is not yet supported in Nuxt 3. If you want to overwrite the default scroll behavior of `vue-router`, you can do so in `~/app/router.options.ts` (see [docs](/docs/guide/recipes/custom-routing#router-options)) for more info.
|
|
107
|
-
Similar to `key`, specify it within the [`definePageMeta`](/docs/api/utils/define-page-meta) compiler macro.
|
|
106
|
+
This feature is not yet supported in Nuxt 3. If you want to overwrite the default scroll behavior of `vue-router`, you can do so in `~/app/router.options.ts` (see [docs](/docs/3.x/guide/recipes/custom-routing#router-options)) for more info.
|
|
107
|
+
Similar to `key`, specify it within the [`definePageMeta`](/docs/3.x/api/utils/define-page-meta) compiler macro.
|
|
108
108
|
|
|
109
109
|
```diff [pages/index.vue]
|
|
110
110
|
- <script>
|
|
@@ -5,16 +5,16 @@ description: 'Learn how to migrate from Nuxt 2 to Nuxt 3 runtime config.'
|
|
|
5
5
|
|
|
6
6
|
If you wish to reference environment variables within your Nuxt 3 app, you will need to use runtime config.
|
|
7
7
|
|
|
8
|
-
When referencing these variables within your components, you will have to use the [`useRuntimeConfig`](/docs/api/composables/use-runtime-config) composable in your setup method (or Nuxt plugin).
|
|
8
|
+
When referencing these variables within your components, you will have to use the [`useRuntimeConfig`](/docs/3.x/api/composables/use-runtime-config) composable in your setup method (or Nuxt plugin).
|
|
9
9
|
|
|
10
|
-
In the `server/` portion of your app, you can use [`useRuntimeConfig`](/docs/api/composables/use-runtime-config) without any import.
|
|
10
|
+
In the `server/` portion of your app, you can use [`useRuntimeConfig`](/docs/3.x/api/composables/use-runtime-config) without any import.
|
|
11
11
|
|
|
12
12
|
:read-more{to="/docs/guide/going-further/runtime-config"}
|
|
13
13
|
|
|
14
14
|
## Migration
|
|
15
15
|
|
|
16
16
|
1. Add any environment variables that you use in your app to the `runtimeConfig` property of the `nuxt.config` file.
|
|
17
|
-
2. Migrate `process.env` to [`useRuntimeConfig`](/docs/api/composables/use-runtime-config) throughout the Vue part of your app.
|
|
17
|
+
2. Migrate `process.env` to [`useRuntimeConfig`](/docs/3.x/api/composables/use-runtime-config) throughout the Vue part of your app.
|
|
18
18
|
|
|
19
19
|
::code-group
|
|
20
20
|
|
|
@@ -25,9 +25,9 @@ export default defineNuxtConfig({
|
|
|
25
25
|
apiSecret: '123',
|
|
26
26
|
// Config within public will be also exposed to the client
|
|
27
27
|
public: {
|
|
28
|
-
apiBase: '/api'
|
|
29
|
-
}
|
|
30
|
-
}
|
|
28
|
+
apiBase: '/api',
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
31
|
})
|
|
32
32
|
```
|
|
33
33
|
|
package/package.json
CHANGED
|
File without changes
|
|
File without changes
|