Skip to content

Commit 4c7c1e5

Browse files
docs: 📝 clarify async components for Vue Router (#1014)
* docs: 📝 clarify async components for Vue Router * Update src/guide/migration/async-components.md PR feedback Co-authored-by: skirtle <[email protected]> * docs: 📝 better examples and names Co-authored-by: skirtle <[email protected]>
1 parent 7599359 commit 4c7c1e5

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/guide/migration/async-components.md

+12-8
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ For a more in-depth explanation, read on!
2020
Previously, async components were created by simply defining a component as a function that returned a promise, such as:
2121

2222
```js
23-
const asyncPage = () => import('./NextPage.vue')
23+
const asyncModal = () => import('./Modal.vue')
2424
```
2525

2626
Or, for the more advanced component syntax with options:
2727

2828
```js
29-
const asyncPage = {
30-
component: () => import('./NextPage.vue'),
29+
const asyncModal = {
30+
component: () => import('./Modal.vue'),
3131
delay: 200,
3232
timeout: 3000,
3333
error: ErrorComponent,
@@ -45,25 +45,29 @@ import ErrorComponent from './components/ErrorComponent.vue'
4545
import LoadingComponent from './components/LoadingComponent.vue'
4646

4747
// Async component without options
48-
const asyncPage = defineAsyncComponent(() => import('./NextPage.vue'))
48+
const asyncModal = defineAsyncComponent(() => import('./Modal.vue'))
4949

5050
// Async component with options
51-
const asyncPageWithOptions = defineAsyncComponent({
52-
loader: () => import('./NextPage.vue'),
51+
const asyncModalWithOptions = defineAsyncComponent({
52+
loader: () => import('./Modal.vue'),
5353
delay: 200,
5454
timeout: 3000,
5555
errorComponent: ErrorComponent,
5656
loadingComponent: LoadingComponent
5757
})
5858
```
5959

60+
::: tip NOTE
61+
Vue Router supports a similar mechanism for asynchronously loading route components, known as *lazy loading*. Despite the similarities, this feature is distinct from Vue's support for async components. You should **not** use `defineAsyncComponent` when configuring route components with Vue Router. You can read more about this in the [Lazy Loading Routes](https://next.router.vuejs.org/guide/advanced/lazy-loading.html) section of the Vue Router documentation.
62+
:::
63+
6064
Another change that has been made from 2.x is that the `component` option is now renamed to `loader` in order to accurately communicate that a component definition cannot be provided directly.
6165

6266
```js{4}
6367
import { defineAsyncComponent } from 'vue'
6468
65-
const asyncPageWithOptions = defineAsyncComponent({
66-
loader: () => import('./NextPage.vue'),
69+
const asyncModalWithOptions = defineAsyncComponent({
70+
loader: () => import('./Modal.vue'),
6771
delay: 200,
6872
timeout: 3000,
6973
errorComponent: ErrorComponent,

0 commit comments

Comments
 (0)