Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 16c6988

Browse filesBrowse files
committed
rename loading/error options, update retry usage
1 parent 7eac42c commit 16c6988
Copy full SHA for 16c6988

File tree

Expand file treeCollapse file tree

1 file changed

+31
-21
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+31
-21
lines changed

‎active-rfcs/0000-async-component-api.md

Copy file name to clipboardExpand all lines: active-rfcs/0000-async-component-api.md
+31-21Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ const AsyncFoo = defineAsyncComponent(() => import("./Foo.vue"))
1717
// with options
1818
const AsyncFooWithOptions = defineAsyncComponent({
1919
loader: () => import("./Foo.vue"),
20-
loading: LoadingComponent,
21-
error: ErrorComponent,
20+
loadingComponent: LoadingComponent,
21+
errorComponent: ErrorComponent,
2222
delay: 200,
2323
timeout: 3000
2424
})
@@ -66,37 +66,47 @@ import { defineAsyncComponent } from "vue"
6666

6767
const AsyncFooWithOptions = defineAsyncComponent({
6868
loader: () => import("./Foo.vue"),
69-
loading: LoadingComponent,
70-
error: ErrorComponent,
69+
loadingComponent: LoadingComponent,
70+
errorComponent: ErrorComponent,
7171
delay: 100, // default: 200
7272
timeout: 3000, // default: Infinity
73-
suspensible: false // default: true
73+
suspensible: false, // default: true
74+
retryWhen: error => error.message.match(/fetch/) // default: () => false
75+
maxRetries: 5 // default: 3
7476
})
7577
```
7678

77-
Options except `loader` and `suspensible` works exactly the same as in 2.x.
79+
- The `delay` and `timeout` options work exactly the same as 2.x.
7880

7981
**Difference from 2.x:**
8082

81-
The `component` option is replaced by the new `loader` option, which accepts the same loader function as in the simple usage.
83+
- The `component` option is replaced by the new `loader` option, which accepts the same loader function as in the simple usage.
8284

83-
In 2.x, an async component with options is defined as
85+
In 2.x, an async component with options is defined as
8486

85-
```ts
86-
() => ({
87-
component: Promise<Component>
88-
// ...other options
89-
})
90-
```
87+
```ts
88+
() => ({
89+
component: Promise<Component>
90+
// ...other options
91+
})
92+
```
9193

92-
Whereas in 3.x it is now:
94+
Whereas in 3.x it is now:
9395

94-
```ts
95-
defineAsyncComponent({
96-
loader: () => Promise<Component>
97-
// ...other options
98-
})
99-
```
96+
```ts
97+
defineAsyncComponent({
98+
loader: () => Promise<Component>
99+
// ...other options
100+
})
101+
```
102+
103+
- 2.x `loading` and `error` options are renamed to `loadingComponent` and `errorComponent` respectively to be more explicit.
104+
105+
## Retry Control
106+
107+
The new `retryWhen` option expects a function that returns a boolean indicating whether the async component should retry when the loader promise rejects. The function receives the rejection error as the argument so it can conditionally retry only on certain types of errors.
108+
109+
The `maxRetries` option determines how many retries are allowed (default: `3`). When max times of retries have been attempted, the component will go into error state (render the `errorComponent` if provided) with the last failed error.
100110

101111
## Using with Suspense
102112

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.