代码如下:
**validateCode:[{validator:(rule, value, callback)=>{
if (!value) {
callback(new Error('you have to input code'))
} else if(this.radioValue=="mobile"){
validatingCo(this.user.mobile,value).then((res)=>{
if(!res.code==20000){
return callback(new Error('the code is wrong or expired'))
} else{
callback()
}
})
}
else{
validatingCo(this.user.email,value).then((res)=>{
if(!res.code==20000){
return callback(new Error('the code is wrong or expired'))
} else{
callback()
}
})
}
}, trigger:'blur'}]
不幸的是,它没有执行,也没有错误。 我想知道如何处理。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
我认为问题可能是由这一行引起的:
if(!res.code==20000){ // Some stuff here }它可能应该是:
if(res.code!=20000){ // Some stuff here }!res.code将始终评估为true或false。所以!res.code==20000将始终为 false。无论输入什么,以下错误回调都不会执行:return callback(new Error('the code is wrong or expired'))这里有一个小演示,展示“bar”总是会被打印出来