如何用Vue和axios实现接收流文件的长尾词?

2026-04-01 12:241阅读0评论SEO基础
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计371个文字,预计阅读时间需要2分钟。

如何用Vue和axios实现接收流文件的长尾词?

在工作中遇到使用axios接收文件时遇到一些问题,整理如下:

在调用接口成功后,如图所示:

现在需要调试axios.js文件,统一拦截输出headers:

// 添加响应拦截器axios.interceptors.response.use(function (response) { // 对响应数据做点什么 const headers=response.headers; console.log(headers); return response;}, function (error) { // 对响应错误做点什么 return Promise.reject(error);});

在工作中遇到使用axios接收流文件,遇到了一些问题,整理如下:

如何用Vue和axios实现接收流文件的长尾词?

在调用接口成功后如图所示:

现在需要调试下axios.js文件统一拦截

// 导出 const headers = response.headers //console.log(headers['content-type']) 将打印的值,也将后台返回的相应头设置成相同的,我的就是'application/octet-stream;charset=UTF-8',然后返回response if (headers['content-type'] == 'application/octet-stream;charset=UTF-8') { return response; }

现在需要注意headers[‘content-type’] 不一定是 ‘application/octet-stream;charset=UTF-8’
在接口调用时需要设置axios的相应类型,responseType: “blob”

this.axios({ method: "get", url: "/dafw/cljsdc", params: data, responseType: "blob" }) .then(res => { let blob = new Blob([_res]); let downloadElement = document.createElement("a"); let href = window.URL.createObjectURL(blob); //创建下载的链接 downloadElement.href = href; downloadElement.download = "xxx.xls"; //下载后文件名 document.body.appendChild(downloadElement); downloadElement.click(); //点击下载 document.body.removeChild(downloadElement); //下载完成移除元素 window.URL.revokeObjectURL(href); //释放掉blob对象 ...

之后就会下载成功…

到此这篇关于vue使用axios接收流文件的实现的文章就介绍到这了,更多相关vue axios接收流文件内容请搜索易盾网络以前的文章或继续浏览下面的相关文章希望大家以后多多支持易盾网络!

本文共计371个文字,预计阅读时间需要2分钟。

如何用Vue和axios实现接收流文件的长尾词?

在工作中遇到使用axios接收文件时遇到一些问题,整理如下:

在调用接口成功后,如图所示:

现在需要调试axios.js文件,统一拦截输出headers:

// 添加响应拦截器axios.interceptors.response.use(function (response) { // 对响应数据做点什么 const headers=response.headers; console.log(headers); return response;}, function (error) { // 对响应错误做点什么 return Promise.reject(error);});

在工作中遇到使用axios接收流文件,遇到了一些问题,整理如下:

如何用Vue和axios实现接收流文件的长尾词?

在调用接口成功后如图所示:

现在需要调试下axios.js文件统一拦截

// 导出 const headers = response.headers //console.log(headers['content-type']) 将打印的值,也将后台返回的相应头设置成相同的,我的就是'application/octet-stream;charset=UTF-8',然后返回response if (headers['content-type'] == 'application/octet-stream;charset=UTF-8') { return response; }

现在需要注意headers[‘content-type’] 不一定是 ‘application/octet-stream;charset=UTF-8’
在接口调用时需要设置axios的相应类型,responseType: “blob”

this.axios({ method: "get", url: "/dafw/cljsdc", params: data, responseType: "blob" }) .then(res => { let blob = new Blob([_res]); let downloadElement = document.createElement("a"); let href = window.URL.createObjectURL(blob); //创建下载的链接 downloadElement.href = href; downloadElement.download = "xxx.xls"; //下载后文件名 document.body.appendChild(downloadElement); downloadElement.click(); //点击下载 document.body.removeChild(downloadElement); //下载完成移除元素 window.URL.revokeObjectURL(href); //释放掉blob对象 ...

之后就会下载成功…

到此这篇关于vue使用axios接收流文件的实现的文章就介绍到这了,更多相关vue axios接收流文件内容请搜索易盾网络以前的文章或继续浏览下面的相关文章希望大家以后多多支持易盾网络!