I ran into problems with element-ui when I executed the promise function in the method. "res" prints out as "undefined" and jumps into ".catch", but in Network the api returns the data normally.Finally I failed to delete
deleteTradeMark(row) {
this.$confirm(`此操作将永久删除${row.tmName}, 是否继续?`, '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(async () => {
let res = await this.$API.trademark.reqDeleteTradeMark(row.id)
console.log(res) // 👈 undefind
if(res.code===200){
this.$message({
type: 'success',
message: '删除成功!'
});
this.getTradeMark(this.list.length>1?this.page:this.page-1)
}
}).catch(() => {
this.$message({
type: 'info',
message: '已取消删除'
});
});
}
export const reqDeleteTradeMark=(id)=>{
request({url:`/api/admin/product/baseTrademark/remove/${id}`,method:'delete'})
}
The api returns code:"200" and delete:" Deleted successfully ".
Why do all the other promises work, is it because of ".then" ?
2
Answers
You should add
return
beforerequest
in `reqDeleteTradeMarkq method.async-await grammar act on Promise, your function reqDeleteTradeMark not return Promise
async-await-grammar