导出文件fileDownload
1、首先安装"js-file-download"依赖
npm install js-file-download --save
2、在所需要的用到的地方导入
import fileDownload from 'js-file-download'
3、使用
import Store from '@/api/Store' // 1、导入导出接口文档
// 2、导出方法
exportEvt() {
Store.directSystemListExport(
{
current:this.state.current,
searchValue:this.state.serachValue,
}
).then((res) => {
fileDownload(res.data,'名称.后缀')
});
}
//3、注意:使用此方法要设置responseType: 'blob',和headers
/* 这是导出接口文档部分内容,在此处设置了responseType和headers
* 导出
*/
static directSystemListExport (data={}){
return request({
url: `xxxxx`,
method: 'post',
responseType: 'blob',
headers: {
'Content-Type': 'application/octet-stream'
},
data
})
}