el-upload 获取上传失败时的返回信息

el-upload 获取上传失败时的返回信息

方案一

直接通过 JSON.parse() 去转换 err.message 而不是转换 err

console.log(JSON.parse(err.message).msg) // 识别发票信息异常!

方案二

把错误信息转成字符串,然后去掉" Error: " ,剩下的内容就是个json,然后再转成对象

console.log(JSON.parse(err.toString().replace('Error: ', '')).msg) // 识别发票信息异常!

example

    handleError(err, file, fileList) {
      console.log(arguments)
      console.log(err) // Error: {"status":400,"code":"-1","msg":"识别发票信息异常!"}
      console.log(err.message) // {"status":400,"code":"-1","msg":"识别发票信息异常!"}
      console.log(err.message.msg) // undefined
      // 方案一 直接通过 JSON.parse() 去转换 err.message 而不是转换 err
      console.log(JSON.parse(err.message).msg) // 识别发票信息异常!
      // 方案二 把错误信息转成字符串,然后去掉" Error: " ,剩下的内容就是个json,然后再转成对象
      console.log(JSON.parse(err.toString().replace('Error: ', '')).msg) // 识别发票信息异常!
      if (file.status === 'fail') {
        this.$message.error(JSON.parse(err.message).msg)
      }
    },
posted @ 2021-11-08 16:44  zc-lee  阅读(897)  评论(0编辑  收藏  举报