Project scene:
I made an error when listening to the teacher talk about the Vue project today.Problem Description:
The items consistently appear XXX is not defined.
data() {
var validatePass = (rule, value, callback) => {
var oldPw = /^[a-zA-Z0-9]{
3,15}$/;
if (value == "") {
callback(new Error("请输入密码"));
} else {
if (!oldPw.test(value)) {
callback(new Error("请输入正确的密码"));
}
callback();
}
};
// var validataPass2 = (rule, value, callback) => {
// var oldPw = /^[a-zA-Z0-9]{3,15}$/;
// if (value == "") {
// callback(new Error("请输入密码"));
// } else if(value!==this.ruleForm.oldPw){
// callback(new Error("两次输入的密码不一致"));
// }else{
// callback();
// }
// }
// };
return {
userName: "",
dialogVisible: false,
name: "海海",
ruleForm: {
oldPw: "",
newPw: "",
age: "",
},
rules: {
oldPw: [{
required: true, validator: validatePass, trigger: "blur" }],
newPw: [{
required: true, validator: validatePass, trigger: "blur" }],
},
};
},
Cause Analysis:
After searching for a long time, it turns out that the validatePass variable is not defined, and the word is mistyped O(∩_∩)O! [Insert image description here](https://img-blog.csdnimg.cn/20201014164142296.png?x-oss- process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQzMDU1ODU1,size_16,color_FFFFFF,t_70#pic_center).solution:
1. It is generally prompted that certain values and variable methods will report this error when the letter is typed incorrectly. Check carefully whether the name of the variable is typed incorrectly.2. Change validataPass to validatePass . When typing code, I always like to type date as data ---- data means data, and date means date .