iview表单部分字段验证方式
单字段验证
this.$refs[formName].validateField(item, (error) => {
console.log(error)
})
多字段验证
const validateField = ['username','password']
Promise.all(validateField.map(field => {
const promise = new Promise(function(resolve, reject) {
this.$refs[formName].validateField(field, (error) => {
resolve(error)
})
})
return promise
})).then((data) => {
if(data.every(i => !i)){
console.log("验证通过")
}else{
console.log(data.join())
}
})