useAsyncValidator
async-validator
のラッパーです。
デモ
@vueuse/integrations アドオンで使用できます。インストール
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
/**
* The validation will be triggered right away for the first time.
* Only works when `manual` is not set to true.
*
* @default true
*/
immediate?: boolean
/**
* If set to true, the validation will not be triggered automatically.
*/
manual?: boolean
}
/**
* Wrapper for async-validator.
*
* @see https://vueuse.dokyumento.jp/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>
ソースコード
貢献者
変更ログ
v12.0.0-beta.1
2024/11/21v10.0.0-beta.4
2023/4/134d757
- feat(types)!: MaybeComputedRef
の名前を MaybeRefOrGetter
に変更10e98
- feat(toRef)!: resolveRef
の名前を toRef
に変更0a72b
- feat(toValue): resolveUnref
の名前を toValue
に変更v10.0.0-beta.2
2023/3/28v10.0.0-beta.1
2023年3月23日v10.0.0-beta.0
2023年3月14日v9.13.0
2023年2月18日v9.11.0
2023年1月17日