Skip to content
On this page

useAsyncValidator

Wrapper for async-validator.

Demo

Category
Export Size
1.2 kB
Package
@vueuse/integrations
Last Changed
last month
Available in the @vueuse/integrations add-on.

Install

bash
npm i async-validator
npm i async-validator

Usage

ts
import { useAsyncValidator } from '@vueuse/integrations/useAsyncValidator'
import { useAsyncValidator } from '@vueuse/integrations/useAsyncValidator'

Type Declarations

typescript
export type AsyncValidatorError = Error & {
  errors: ValidateError[]
  fields: Record<string, ValidateError[]>
}
export interface UseAsyncValidatorReturn {
  pass: Ref<boolean>
  errorInfo: Ref<AsyncValidatorError | null>
  isFinished: Ref<boolean>
  errors: Ref<AsyncValidatorError["errors"] | undefined>
  errorFields: Ref<AsyncValidatorError["fields"] | undefined>
}
export interface UseAsyncValidatorOptions {
  /**
   * @see https://github.com/yiminghe/async-validator#options
   */
  validateOption?: ValidateOption
}
/**
 * Wrapper for async-validator.
 *
 * @see https://vueuse.org/useAsyncValidator
 * @see https://github.com/yiminghe/async-validator
 */
export declare function useAsyncValidator(
  value: MaybeComputedRef<Record<string, any>>,
  rules: MaybeComputedRef<Rules>,
  options?: UseAsyncValidatorOptions
): UseAsyncValidatorReturn & PromiseLike<UseAsyncValidatorReturn>
export type AsyncValidatorError = Error & {
  errors: ValidateError[]
  fields: Record<string, ValidateError[]>
}
export interface UseAsyncValidatorReturn {
  pass: Ref<boolean>
  errorInfo: Ref<AsyncValidatorError | null>
  isFinished: Ref<boolean>
  errors: Ref<AsyncValidatorError["errors"] | undefined>
  errorFields: Ref<AsyncValidatorError["fields"] | undefined>
}
export interface UseAsyncValidatorOptions {
  /**
   * @see https://github.com/yiminghe/async-validator#options
   */
  validateOption?: ValidateOption
}
/**
 * Wrapper for async-validator.
 *
 * @see https://vueuse.org/useAsyncValidator
 * @see https://github.com/yiminghe/async-validator
 */
export declare function useAsyncValidator(
  value: MaybeComputedRef<Record<string, any>>,
  rules: MaybeComputedRef<Rules>,
  options?: UseAsyncValidatorOptions
): UseAsyncValidatorReturn & PromiseLike<UseAsyncValidatorReturn>

Source

SourceDemoDocs

贡献者(Contributors)

日志(Changelog)

Pending for release...
93b45 - fix: incorrect condition for choosing constructor (#2788)
v9.13.0 on 2023/2/18
dbcdb - fix: fix Schema importing from async-validator (#2761)

Released under the MIT License.