Professional Documents
Culture Documents
5
5
interface AsyncComponentOptions {
loader: Function
loadingComponent?: any
errorComponent?: any
delay?: number
timeout?: number
suspensible?: boolean
onError?: (
error: Error,
retry: () => void,
fail: () => void,
attempts: number
) => any
}
/**
* v3-compatible async component API.
* @internal the type is manually declared in <root>/types/v3-define-async-
component.d.ts
* because it relies on existing manual types
*/
export function defineAsyncComponent(
source: (() => any) | AsyncComponentOptions
): AsyncComponentFactory {
if (isFunction(source)) {
source = { loader: source } as AsyncComponentOptions
}
const {
loader,
loadingComponent,
errorComponent,
delay = 200,
timeout, // undefined = never times out
suspensible = false, // in Vue 3 default is true
onError: userOnError
} = source
let retries = 0
const retry = () => {
retries++
pendingRequest = null
return load()
}
return () => {
const component = load()
return {
component,
delay,
timeout,
error: errorComponent,
loading: loadingComponent
}
}
}