我想检查vatnumber是否有效,但是我的async-await无法像我想要的那样工作,因为它已经在验证之前返回。
增值税号无效(控制台)
具有有效的增值税号(控制台)
测试2个未定义
{countryCode:“ **”,增值税编号:“ **********”,requestDate:“ 2018-08-29 + 02:00”,有效:true,名称:“ ******“,...}
测试1次正确
Model.vue:
import validate from 'validate-vat'
Validator.extend('vatnumber', {
getMessage: field => 'The ' + field + ' is not valid.',
validate: async value => {
let vatnumber = value.replace(/\s/g, '')
let countryCode = vatnumber.substring(0, 2).toUpperCase()
let vatnumberCode = vatnumber.substring(2)
let isValid = false
isValid = await validate(countryCode, vatnumberCode, function (err, validationInfo) {
let isVat = false
console.log(validationInfo, err)
if (validationInfo.valid) {
isVat = true
console.log('test 1', isVat)
}
return isVat
})
console.log('test 2', isValid)
return isValid
}
})