一:安装 js-file-download
npm install js-file-download
二:引用 js-file-download
import fileDownload from "js-file-download";
三:调用 js-file-download
// 导出excel
exportExcel(){
//封装查询参数data
let data = {
param: this.searchData,
};
this.$confirm('确定导出?','操作提示',{
confirmButtonText:'确定',
cancelButtonText:'取消',
type:'warning',
}).then(()=>{
//调用java接口,取到java返回的文件流,定义类型为blob
exportExcel(data,{ responseType: "blob" }).then( (res) => {
let date= this.getDate();
//调用fileDownload
fileDownload(res.data, "陕西公司厂内车辆.xlsx");
this.$message({
message: '成功!',
type: 'success'
});
})
})
},
四:声明接口返回值类型
'responseType':"arraybuffer"或者'responseType':"blob"
注:arraybuffer 和blob类型都行
export const exportExcel = (data) => {
return axios({
url: prefix + 'base/BasePlanDay/exportExcel',
headers: {'isMork': false},
method: 'post',
data,
'responseType':"arraybuffer"
})
}
END...SEE YOU