Vue.prototype.$xlsx_get = function (url, data, fun, err) { axios({ method: 'get', url: url, responseType: "blob", headers: { 'Authorization': userName ? userName.token_type + userName.access_token : "Basic emh4eTp6aHh5" }, params: data, }).then(function (res) { if (fun) { fun(res) } }) .catch(function (error) { if (err) { err(error) } }); }
// 下载 downLoadClick(row) { console.log(row); this.$xlsx_get( `/dcenter/backup/download/${row.id}`, {}, res => {
const blob = new Blob([res]);
console.log(blob);
const elink = document.createElement("a");
const fileName = '名字.xlsx';
elink.download = fileName;
elink.style.display = "none";
elink.href = URL.createObjectURL(blob);
document.body.appendChild(elink);
elink.click();
URL.revokeObjectURL(elink.href); // 释放URL 对象
document.body.removeChild(elink);
this.isDefault = false
this.$message.success("导出成功");
console.log(res); }, err => { this.$message.error(err.msg) throw err; } ); },
下载这种文件流的方式