请问使用axios可以绑定请求id吗

页面是一个tree,可以点击修改,想支持某个节点在请求修改时loading,此时也可以并行修改其他节点,当上个节点请求失败则返回错误,停止对应节点的loading。

现在发现catch中拿不到对应请求失败的节点id,不知道axios支持设置某个请求id吗,或者我该如何将id传入catch中

if (this.moduleNodeQuery.currentId > 0) {
        this.requestEditing[data.id] = true
        editModule(this.moduleNodeQuery).then(response => {
          this.requestEditing[data.id] = false
          const id = response.data.id
          this.tmpNodeData[id].label = response.data.moduleName
          this.tmpNodeData[id].owner = response.data.owner
          this.moduleNodeQuery.currentId = -1
          this.$message({
            message: 'edit success',
            type: 'success'
          })
          if (callback) {
            callback()
          }
        }).catch(() => {
          this.$message({
            message: 'edit error',
            type: 'error'
          })
          
          这里该如何写,Id获取不到啊
          this.requestEditing[Id?] = false
        })
阅读 1.9k
1 个回答

catch 也有参数 可以选择

catch(err => {
    console.log(err.id)
})
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题