vue项目中如何实现以blob形式导出文件-创新互联
这篇文章将为大家详细讲解有关vue项目中如何实现以blob形式导出文件,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。
1、首先要确定服务器返回的数据类型。
在请求头中加入: config.responseType = 'blob'
有时候,不是所有接口都需要该类型,则可以对接口做一个判定:
// request拦截器 service.interceptors.request.use( config => { // 根据接口判定 if ( config.url === '/setting/exportData' || config.url.indexOf('export') > -1 || config.url.indexOf('Export') > -1) { config.responseType = 'blob' // 服务请求类型 } if (getToken()) { config.headers['access_token'] = getToken() } return config }, error => { // Do something with request error // console.log(error) // for debug Promise.reject(error) } )
本文名称:vue项目中如何实现以blob形式导出文件-创新互联
分享路径:http://ybzwz.com/article/iocco.html