作为前端,表单验证很重要了。本博客主要介绍对vee-validate在实际项目中进一步封装使用。
-
引入vee-validate
-
npm install [email protected]
-
注意版本号,此版本中文包支持的最好。
2. 引入基本配置,在main.js里加入下面代码
//validator
import VeeValidate, {Validator} from 'vee-validate'
import zh from 'vee-validate/dist/locale/zh_CN'// 引入中文文件
// 配置中文
Validator.addLocale(zh) const config = {
errorBagName: 'errors', // change if property conflicts.
fieldsBagName: 'fieldBags', // 报冲突时 可自定义修改字段名称
delay: 0, // 错误提示的延迟时间
strict: true, // 没有设置规则的表单不进行校验,
enableAutoClasses: false,
locale: 'zh_CN', // 对语言(中文)的配置
classNames: {
touched: 'touched', // the control has been blurred
untouched: 'untouched', // the control hasn't been