skip to Main Content

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'})
}

enter image description here
The api returns code:"200" and delete:" Deleted successfully ".

Why do all the other promises work, is it because of ".then" ?

2

Answers


  1. You should add return before request in `reqDeleteTradeMarkq method.

    export  const  reqDeleteTradeMark=(id)=>{
          return request({url:`/api/admin/product/baseTrademark/remove/${id}`,method:'delete'})
    }
    
    Login or Signup to reply.
  2. async-await grammar act on Promise, your function reqDeleteTradeMark not return Promise
    async-await-grammar

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search