async checkDriver(mobile) {
this.$axios({
url: "xxx",
method: "POST",
data: {
mobile: mobile
}
}).then(res => {
console.log("========="+res.status);
return res.data.status;
}).catch(error => {
this.$message.error(error.toString());
return -1;
});
},
addValidate() {
this.$refs['form'].validate((valid) => {
if (valid) {
let status = await this.checkDriver(this.form.mobile);
console.log(status);
} else {
return false;
}
});
Unresolved variable or type await.Highlights functions that were possibly intended to be async but are missing the async modifier.How to use await in =>?Give me some help.Thanks
The async
keyword must be used for the function that USES await in its body.
So, move async
from checkDriver
to addValidate
:
checkDriver(mobile) {
// ...
}
async addValidate() {
// ...
let status = await this.checkDriver(this.form.mobile);
}
Also, the checkDriver
method should return a promise. So change the contents of checkDriver
to:
checkDriver(mobile) {
return this.$axios({
url: "xxx",
method: "POST",
data: {
mobile: mobile
}
})
}
and the data returned from the Promise (axios in this case) will be assigned to status
in addValidate
Then if you want to handle errors, you should wrap the await
call in a try/catch block.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With