1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
| data(){ var validateOldPass = (rule,value,callback) => { if(value === ''){ callback(new Error('旧密码不能为空!')) }else{ callback() } };
var validatePass = (rule, value, callback) => { if (value === '') { callback(new Error('请输入新密码')); }else if(value === this.ruleForm.oldPass){ callback(new Error('新旧密码不能一样!')) } else { if (this.ruleForm.checkPass !== '') { this.$refs.ruleForm.validateField('checkPass'); } callback(); } }; var validatePass2 = (rule, value, callback) => { if (value === '') { callback(new Error('请再次输入新密码')); } else if (value !== this.ruleForm.pass) { callback(new Error('两次输入密码不一致!')); } else { callback(); } }; return { ruleForm: { oldPass:'', pass: '', checkPass: '',
}, rules: { oldPass: [ { validator: validateOldPass, trigger: 'blur' } ], pass: [ { validator: validatePass, trigger: 'blur' } ], checkPass: [ { validator: validatePass2, trigger: 'blur' } ],
}
}; }, methods: { checkForm(formName,e) { this.$refs[formName].validate((valid) => { if (valid) { alert('submit!'); } else { console.log('error submit!!'); e.preventDefault() } }); }, resetForm(formName) { this.$refs[formName].resetFields(); } }
|