Skip to content

Commit a64607c

Browse files
committed
async component
omitted the error retry feature because it is somewhat useless when combined with native dynamic import caching behavior
1 parent fc59eae commit a64607c

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

src/guide/components/async.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Async Components
22

3+
## Basic Usage
4+
35
In large applications, we may need to divide the app into smaller chunks and only load a component from the server when it's needed. To make that possible, Vue has a [`defineAsyncComponent`](/api/general.html#defineasynccomponent) method:
46

57
```js
@@ -47,9 +49,31 @@ export default {
4749

4850
</div>
4951

50-
## Loading State
52+
## Loading and Error States
53+
54+
Asynchronous operations inevitably involve loading and error states - `defineAsyncComponent()` supports handling these states via advanced options:
55+
56+
```js
57+
const AsyncComp = defineAsyncComponent({
58+
// the loader function
59+
loader: () => import('./Foo.vue'),
60+
61+
// A component to use while the async component is loading
62+
loadingComponent: LoadingComponent,
63+
// Delay before showing the loading component. Default: 200ms.
64+
delay: 200,
65+
66+
// A component to use if the load fails
67+
errorComponent: ErrorComponent,
68+
// The error component will be displayed if a timeout is
69+
// provided and exceeded. Default: Infinity.
70+
timeout: 3000
71+
})
72+
```
73+
74+
If a loading component is provided, it will be displayed first while the inner component is being loaded. There is a default 200ms delay before the loading component is shown - this is because on fast networks, an instant loading state may get replaced too fast and end up looking like a flicker.
5175

52-
## Error Handling
76+
If an error component is provided, it will be displayed when the Promise returned by the loader function is rejected. You can also specify a timeout to show the error component when the request is taking too long.
5377

5478
## Using with Suspense
5579

0 commit comments

Comments
 (0)