vee-validate-skilld
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chineselogaretm/vee-validate vee-validate
vee-validatelogaretm/vee-validate vee-validate
vee-validateVersion: 4.15.1 (Jun 2025)
Deps: @vue/devtools-api@^7.5.2, type-fest@^4.8.3
Tags: prev: 1.0.0-beta.10 (Nov 2016), next-edge: 4.5.0-alpha.2 (Jul 2021), edge: 4.5.0-alpha.6 (Aug 2021), next: 4.5.8 (Jan 2022), alpha: 4.12.0-alpha.1 (Nov 2023), beta: 5.0.0-beta.0 (Aug 2025), latest: 4.15.1 (Jun 2025)
References: Docs — API reference, guides • GitHub Issues — bugs, workarounds, edge cases • Releases — changelog, breaking changes, new APIs
版本: 4.15.1(2025年6月)
依赖: @vue/devtools-api@^7.5.2, type-fest@^4.8.3
标签: prev: 1.0.0-beta.10(2016年11月), next-edge: 4.5.0-alpha.2(2021年7月), edge: 4.5.0-alpha.6(2021年8月), next: 4.5.8(2022年1月), alpha: 4.12.0-alpha.1(2023年11月), beta: 5.0.0-beta.0(2025年8月), latest: 4.15.1(2025年6月)
参考资料: 文档 — API参考、指南 • GitHub问题 — 漏洞、解决方案、边缘情况 • 版本发布 — 更新日志、破坏性变更、新API
API Changes
API变更
This section documents version-specific API changes for vee-validate v4.x — prioritize these over legacy patterns.
-
BREAKING:support disabled by default in v4.10.0 for performance; enable via
v-modelor per-fieldconfigure({ validateOnModelUpdate: true })sourcesyncVModel -
NEW:introduced in v4.9.0 — replaces
defineFieldanddefineComponentBindsfor cleaner Composition API integration sourcedefineInputBinds -
DEPRECATED: Reactive initial values deprecated in v4.12.0; use non-reactive objects or getters to prevent unintended sync source
-
NEW:exposed in v4.14.0 for accessing form state in deeply nested components without manual injection source
useFormContext -
NEW:exposed on
setValueinstances and slot props in v4.13.0 for manual value updates sourceField -
NEW: Composition setter hooks (,
useSetFieldValue,useSetFormValues) added in v4.11.0 for external state management sourceuseSetFormErrors -
NEW:accepts
handleBlurparameter since v4.10.0 to control validation triggers on blur events sourceshouldValidate -
NEW:accepts target model prop name as a string in v4.10.0 for custom model support source
syncVModel -
NEW:state added to
isValidatingand form slot props in v4.9.3 to track async validation status sourceuseForm -
NEW:added to
move(oldIdx, newIdx)in v4.6.0 for reordering items within array fields sourceFieldArray -
NEW: Specialized state hooks (,
useIsFieldDirty,useIsFormValid) added in v4.1.0 for granular state access sourceuseFieldValue -
DEPRECATED:deprecated in v4.4.0; use
handleInputfor both input and change events sourcehandleChange -
NEW:support in
labeladded in v4.12.0 for consistent error message generation sourcedefineField -
NEW:with
ResetFormOptsflag added toforcein v4.13.0 to clear values without merging sourceuseResetForm
Also changed: deprecated · deprecated · deprecated · config added · reactivity improved · validate returns object · hook added · new v4.12.3
defineComponentBindsdefineInputBindsuseFieldModelunsetValueOnUnmountkeepValuesOnUnmountuseFormuseResetFormnested field meta querying本节记录vee-validate v4.x版本特有的API变更 — 优先遵循这些内容而非旧有模式。
-
破坏性变更:v4.10.0中默认禁用支持以提升性能;可通过
v-model或为单个字段设置configure({ validateOnModelUpdate: true })来启用 来源syncVModel -
新增特性:v4.9.0中引入— 替代
defineField和defineComponentBinds,实现更简洁的Composition API集成 来源defineInputBinds -
已弃用:v4.12.0中弃用响应式初始值;使用非响应式对象或getter避免意外同步 来源
-
新增特性:v4.14.0中暴露,无需手动注入即可在深层嵌套组件中访问表单状态 来源
useFormContext -
新增特性:v4.13.0中在实例和插槽props上暴露
Field,用于手动更新值 来源setValue -
新增特性:v4.11.0中添加组合式设置器钩子(,
useSetFieldValue,useSetFormValues),用于外部状态管理 来源useSetFormErrors -
新增特性:自v4.10.0起,接受
handleBlur参数,用于控制失焦事件触发的验证行为 来源shouldValidate -
新增特性:v4.10.0中接受目标model属性名称作为字符串,支持自定义model 来源
syncVModel -
新增特性:v4.9.3中为和表单插槽props添加
useForm状态,用于跟踪异步验证状态 来源isValidating -
新增特性:v4.6.0中为添加
FieldArray,用于重新排序数组字段内的项 来源move(oldIdx, newIdx) -
新增特性:v4.1.0中添加专用状态钩子(,
useIsFieldDirty,useIsFormValid),用于细粒度状态访问 来源useFieldValue -
已弃用:v4.4.0中弃用;使用
handleInput处理输入和变更事件 来源handleChange -
新增特性:v4.12.0中为添加
defineField支持,用于生成一致的错误信息 来源label -
新增特性:v4.13.0中为添加带
useResetForm标志的force,无需合并即可清除值 来源ResetFormOpts
其他变更: 已弃用 · 已弃用 · 已弃用 · 添加配置 · 改进响应式 · 的validate方法返回对象 · 添加钩子 · 新增v4.12.3的嵌套字段元数据查询
defineComponentBindsdefineInputBindsuseFieldModelunsetValueOnUnmountkeepValuesOnUnmountuseFormuseResetFormBest Practices
最佳实践
- Prefer for binding components and inputs — returns a
defineField()ref and a props object for clean, non-deprecated binding sourcev-model
ts
const [email, emailProps] = defineField('email', {
validateOnBlur: true,
props: state => ({ 'aria-invalid': !!state.errors.length })
});-
Display errors conditionally using— prevents "aggressive" validation where error messages appear before the user interacts with the field source
meta.touched -
Usefor comprehensive TypeScript safety — wraps Yup, Zod, or Valibot schemas to differentiate between input (UI) and output (submitted) types source
toTypedSchema()
ts
import { toTypedSchema } from '@vee-validate/zod';
import * as z from 'zod';
const { values } = useForm({
validationSchema: toTypedSchema(z.object({ email: z.string().email() }))
});-
Mark validation schemas as non-reactive — wrap schemas inor declare them outside of
markRaw/refto avoid unnecessary deep reactivity overhead sourcereactive -
Tree-shake schema validator imports — only import the specific functions you need (e.g.,) to keep bundle sizes to a minimum source
import { string } from 'yup' -
Pass reactive field names as getters in— use a function (e.g.,
useField) to ensure vee-validate tracks name changes in dynamic forms source() => props.name -
Enablefor multi-step forms — preserves field state when components are hidden via
keepValuesOnUnmountor tab switching sourcev-if
ts
const { values } = useForm({
keepValuesOnUnmount: true
});-
Usefor stable iteration in
field.key—v-forprovides unique identifiers that persist through array operations, unlike indices sourceuseFieldArray -
Escape field names withto disable automatic nesting — wrap names (e.g.,
[]) to treat dots as literal characters rather than object paths source[user.name] -
Filter submission values with— ensures only fields explicitly registered via
handleSubmit.withControlled()oruseFieldare included in the payload sourcedefineField
- 优先使用绑定组件和输入框 — 返回
defineField()引用和props对象,实现简洁且未被弃用的绑定方式 来源v-model
ts
const [email, emailProps] = defineField('email', {
validateOnBlur: true,
props: state => ({ 'aria-invalid': !!state.errors.length })
});-
使用条件显示错误信息 — 避免在用户与字段交互前就显示错误信息的"激进"验证方式 来源
meta.touched -
使用实现全面的TypeScript类型安全 — 包装Yup、Zod或Valibot schema,区分输入(UI)和输出(提交)类型 来源
toTypedSchema()
ts
import { toTypedSchema } from '@vee-validate/zod';
import * as z from 'zod';
const { values } = useForm({
validationSchema: toTypedSchema(z.object({ email: z.string().email() }))
});-
将验证schema标记为非响应式 — 使用包装schema或在
markRaw/ref外部声明,避免不必要的深度响应式开销 来源reactive -
按需导入schema验证器函数 — 仅导入所需的特定函数(如),最小化包体积 来源
import { string } from 'yup' -
在中以getter形式传递响应式字段名称 — 使用函数(如
useField)确保vee-validate跟踪动态表单中的名称变更 来源() => props.name -
为多步骤表单启用— 当组件通过
keepValuesOnUnmount或标签切换隐藏时保留字段状态 来源v-if
ts
const { values } = useForm({
keepValuesOnUnmount: true
});-
在中使用
v-for实现稳定迭代 —field.key提供的唯一标识符在数组操作中保持不变,不同于索引 来源useFieldArray -
使用转义字段名称以禁用自动嵌套 — 包裹名称(如
[]),将点视为字面量字符而非对象路径 来源[user.name] -
使用过滤提交值 — 确保仅包含通过
handleSubmit.withControlled()或useField显式注册的字段 来源defineField