Changing passwords Sometimes, you need to enter the old password, new password, and confirm password. The new password and confirm password must be the same. If they are different, a message is displayed

The effect is as follows

First, write the input field

<el-form-item label=" Modify password :" prop="newPassword"> <el-input V-model ="addForm. NewPassword "type="password" /> </el-form-item> <el-form-item label=" confirmPassword :" prop="confirmPassword"> < EL-Input V-model ="addForm.confirmPassword" type="password" /> </el-form-item>Copy the code

And then define the rules

Var validatePass = (rule, value, callback) => {if (value === "") {callback(new Error(" Please input password ")); } else { if (this.addForm.confirmPassword ! == "") { this.$refs.addForm.validateField("confirmPassword"); } callback(); }}; Var validatePass2 = (rule, value, callback) => {if (value === "") {callback(new Error(" please input password again ")); } else if (value ! == this.addform. newPassword) {callback(new Error) )); } else { callback(); }};Copy the code

Redefining data

 addForm: {   
                newPassword: "",

                confirmPassword: ""
            },

Copy the code

Add to the validation rule

// Form validation addRules: {newPassword: [{validator: validatePass, trigger: ["blur", "change"]}], confirmPassword: [ { validator: validatePass2, trigger: ["blur", "change"] } ] },Copy the code

That will do

References:

Blog.csdn.net/qq_42546652…