blob下载word后内容不对

后台返回的数据

img

这是下载方法,请求接口也设置了 responseType: "blob",

img


打开下载的word文档,内容不对

img

  1. 按你的思路来,要后端改代码,需要返回的是word流,而不是json
  2. 按后端的思路来,你改代码,返回的是JSON,但是后端要告诉你result字段格式的编码,你按正常的json取,然后转换为byte,再new Blob,字段取的层级为res[1].data.result

responseType 需要设置blob
比如

// HTTP---request拦截
axios.interceptors.request.use(config => {
  config.responseType = 'blob';
  return config
}, error => {
  return Promise.reject(error)
});

然后,请求结果,需要转换:
比如:

let reader = new FileReader();
    // 有传递编码格式,用已有的,没有默认utf-8
    charset = store.getters.cache.charset;
    charset = charset || charset_utf8;
    reader.readAsText(res, charset);
    reader.onload = function (e) {
      console.log('blob源文件结果:', reader.result);
      let resData = d3.csvParse(reader.result);
      console.log('格式化json结果:', resData);
      resolve(resData)
    };

最后,请采纳,谢谢

后端返回的内容不对,有后端源码的话,建议把后端接口源码贴出来

blob 下载文件后,获取后台错误信息
https://www.cnblogs.com/DL-CODER/p/16634983.html