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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM