点击按钮调接口
this.$axios.post(
defaultSettings.filePath + '/api/equipmentappservicecs/exporteqtequipmentexcel', {},
{
headers: { "Content-Type": "application/json; charset=utf-8", "Authorization": window.sessionStorage.getItem("token") },
responseType: 'blob'
}).then(ok => {
this.downloadnew(ok.data, 'application/vnd.ms-excel;charset=UTF-8', 'Equipment2021/11/12.xlsx')
})
注意responseType: 'blob'是重点
downloadnew(res, type, filename) {//返回的文件流,格式,保存的文件名字
// 创建blob对象,解析流数据
const blob = new Blob([res], {
// 设置返回的文件类型
// type: 'application/pdf;charset=UTF-8' 表示下载文档为pdf,如果是word则设置为msword,excel为excel