Skip to content

Commit fb76958

Browse files
Extend the examples for async components (#1808)
1 parent 3fbcc56 commit fb76958

File tree

1 file changed

+38
-5
lines changed

1 file changed

+38
-5
lines changed

src/guide/components/async.md

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,56 @@ const AsyncComp = defineAsyncComponent(() =>
2828
)
2929
```
3030

31-
The resulting `AsyncComp` is a wrapper component that only calls the loader function when it is actually rendered on the page. In addition, it will pass along any props to the inner component, so you can use the async wrapper to seamlessly replace the original component while achieving lazy loading.
31+
The resulting `AsyncComp` is a wrapper component that only calls the loader function when it is actually rendered on the page. In addition, it will pass along any props and slots to the inner component, so you can use the async wrapper to seamlessly replace the original component while achieving lazy loading.
32+
33+
As with normal components, async components can be [registered globally](/guide/components/registration.html#global-registration) using `app.component()`:
34+
35+
```js
36+
app.component('MyComponent', defineAsyncComponent(() =>
37+
import('./components/MyComponent.vue')
38+
))
39+
```
3240

3341
<div class="options-api">
3442

3543
You can also use `defineAsyncComponent` when [registering a component locally](/guide/components/registration.html#local-registration):
3644

37-
```js
45+
```vue
46+
<script>
3847
import { defineAsyncComponent } from 'vue'
3948
4049
export default {
41-
// ...
4250
components: {
43-
AsyncComponent: defineAsyncComponent(() =>
44-
import('./components/AsyncComponent.vue')
51+
AdminPage: defineAsyncComponent(() =>
52+
import('./components/AdminPageComponent.vue')
4553
)
4654
}
4755
}
56+
</script>
57+
58+
<template>
59+
<AdminPage />
60+
</template>
61+
```
62+
63+
</div>
64+
65+
<div class="composition-api">
66+
67+
They can also be defined directly inside their parent component:
68+
69+
```vue
70+
<script setup>
71+
import { defineAsyncComponent } from 'vue'
72+
73+
const AdminPage = defineAsyncComponent(() =>
74+
import('./components/AdminPageComponent.vue')
75+
)
76+
</script>
77+
78+
<template>
79+
<AdminPage />
80+
</template>
4881
```
4982

5083
</div>

0 commit comments

Comments
 (0)