1、获取第一次输入的密码的值
2、比较两次密码的值是否相等
3、如果不一致返回错误信息
this.userInfo.password2:获取第一次输入的密码;value当前校验值;validator自定义校验规则;
const ConfirmPassword = (rule, value, callback) => {
if (value !== this.userInfo.password2) {
callback(new Error('两次输入密码不一致!'))
} else {
callback()
}
}
userInfo: {
username: '',
password2: '',
password3: ''
},
rules: {
username: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
password2: [{ required: true, message: '请输入密码', trigger: 'blur' },
{ min: 6, max: 9, message: '密码长度6-9位', trigger: 'blur'}],
password3: [{ required: true, message: '确认密码不能为空', trigger: 'blur' },
{ trigger: 'blur', validator: ConfirmPassword }]
}
标签:password2,vue,校验,表单,密码,trigger,blur,message,输入
From: https://blog.51cto.com/u_15961699/8658156