<el-form ref="ruleForm" :rules="rules" :model="ruleForm"> <el-form-item label="旧密码" prop="userName"> <el-input v-model.trim="ruleForm.userName" placeholder="请输入旧密码"></el-input> </el-form-item> <el-form-item label="密码" prop="password"> <el-input v-model.trim="ruleForm.password" placeholder="请输入密码" maxLength="32"></el-input> </el-form-item> <el-form-item label="确认密码" prop="password1"> <el-input v-model.trim="ruleForm.password1" placeholder="请输入确认密码" maxLength="32"></el-input> </el-form-item> </el-form>
export default { // name: "登录密码", data() { const validatePhone = (rule, value, callback) => { const reg = /^1[3456789]\d{9}$/ const reg1 = /^0\d{2,3}-?\d{7,8}$/ if (reg.test(value) == true || reg1.test(value) == true) { callback() } else if (value == '') { callback(new Error('请输入手机号码')) } else { callback(new Error('手机号码格式错误')) } } const validatePsd1 = (rule, value, callback) => { if (value == '') { callback(new Error('请输入确认密码')) } else if (this.ruleForm.password == '') { callback(new Error('请先输入密码')) this.ruleForm.password1 = '' } else if (value != this.ruleForm.password) { callback(new Error('确认密码与密码不一致')) } else { callback() } } const validatePsd = (rule, value, callback) => { if (value == '') { callback(new Error('请输入密码')) } else if (this.ruleForm.password == '') { callback(new Error('请输入密码')) } else if (value.length<6||value.length>32) { callback(new Error('密码不少于6位,不大于32位')) } else { callback() } } return { loading: false, ruleForm: { userName: '', password: '', password1: '' }, rules: { userName: [{ required: true, message: '请输入旧密码', trigger: 'blur' }], password: [{ required: true,validator: validatePsd, trigger: 'blur' }], password1: [{ required: true, validator: validatePsd1, trigger: 'blur' }] } } }, watch: {}, mounted() { }, methods: { }, onSubmit(formName) { this.$refs[formName].validate(valid => { if (this.ruleForm.password1 == this.ruleForm.password) { if (valid) { this.loading = true let obj = { userName: this.ruleForm.userName, password: this.ruleForm.password, password1: this.ruleForm.password1 } if (this.ruleForm.password != '') { obj.pwd = md5(this.ruleForm.password) } //调用接口 editUser(obj) .then(response => { this.loading = false if (response.code == 200) { this.$message({ message: '更新成功!', type: 'success' }) this.$router.push({ path: '/setting/user' }) } }) .catch(error => { this.loading = false reject(error) }) } } else { console.log(this.ruleForm.password) console.log(this.ruleForm.password1) this.$message({ message: '密码与确认密码不一致!', type: 'warning' }) } }) } } } </script>
标签:修改,验证,value,else,ruleForm,密码,callback,password From: https://www.cnblogs.com/shuihanxiao/p/16599674.html