useAsyncValidator
对 async-validator
的封装。
Demo
Available in the @vueuse/integrations add-on.安装
bash
npm i async-validator@^4
用法
ts
import { useAsyncValidator } from '@vueuse/integrations/useAsyncValidator'
js
export {}
类型声明
显示类型声明
typescript
export type AsyncValidatorError = Error & {
errors: ValidateError[]
fields: Record<string, ValidateError[]>
}
export interface UseAsyncValidatorExecuteReturn {
pass: boolean
errors: AsyncValidatorError["errors"] | undefined
errorInfo: AsyncValidatorError | null
errorFields: AsyncValidatorError["fields"] | undefined
}
export interface UseAsyncValidatorReturn {
pass: Ref<boolean>
isFinished: Ref<boolean>
errors: Ref<AsyncValidatorError["errors"] | undefined>
errorInfo: Ref<AsyncValidatorError | null>
errorFields: Ref<AsyncValidatorError["fields"] | undefined>
execute: () => Promise<UseAsyncValidatorExecuteReturn>
}
export interface UseAsyncValidatorOptions {
/**
* @see https://github.com/yiminghe/async-validator#options
*/
validateOption?: ValidateOption
/**
* 第一次将会立即触发验证。
* 当 `manual` 设置为 true 时才有效。
*
* @default true
*/
immediate?: boolean
/**
* 如果设置为 true,验证将不会自动触发。
*/
manual?: boolean
}
/**
* async-validator 的包装器。
*
* @see https://vueuse.org/useAsyncValidator
* @see https://github.com/yiminghe/async-validator
*/
export declare function useAsyncValidator(
value: MaybeRefOrGetter<Record<string, any>>,
rules: MaybeRefOrGetter<Rules>,
options?: UseAsyncValidatorOptions,
): UseAsyncValidatorReturn & PromiseLike<UseAsyncValidatorReturn>
Source
贡献者
Anthony Fu
丶远方
Jaw
Jelf
Anthony Fu
Doctorwu
류한경
Bakhtiyor Ruziev
Bakhtiyor Ruziev
Hawtim
vaakian X
Curt Grimes
变更日志
v10.0.0-beta.4
on 4/13/20234d757
- feat(types)!: rename MaybeComputedRef
to MaybeRefOrGetter
10e98
- feat(toRef)!: rename resolveRef
to toRef
0a72b
- feat(toValue): rename resolveUnref
to toValue
v10.0.0-beta.2
on 3/28/2023v10.0.0-beta.1
on 3/23/2023v10.0.0-beta.0
on 3/14/2023v9.13.0
on 2/18/2023v9.11.0
on 1/17/2023