vueバックエンドからのexcelのダウンロード(フロントエンドでないexcelの生成)
vueダウンロードバックエンドから与えられたexcelは主にファイルストリームの処理htmlを要求する.
js:
<el-button size="mini" @click="downexcel"> </el-button>
js:
downexcel() {
axios({
method: "get",
url: SERVER_BASE_URL + "invoice/saledetail/tempDownload",// SERVER_BASE_URL
// headers token
headers: {
"Content-Type": "multipart/form-data",
token: getToken()//token
},
// , blob, json
responseType: "blob"
}).then(res => {
const link = document.createElement("a");
const blob = new Blob([res.data], {
type: "application/vnd.ms-excel" });
link.style.display = "none";
link.href = URL.createObjectURL(blob);
link.setAttribute("download", "xxx .xls");
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
});
},