场景:
一个自定义的按钮,点击下载一个后端传过来的文件
代码:
// 下载
$downLoad(filename, content) {
const blob = new Blob([content]);
const downloadElement = document.createElement('a', { type: 'application/vnd.ms-excel' });
const href = window.URL.createObjectURL(blob);
downloadElement.href = href;
downloadElement.download = filename;
document.body.appendChild(downloadElement);
downloadElement.click();
document.body.removeChild(downloadElement);
window.URL.revokeObjectURL(href);
},
使用方法:
<el-button size="small" @click="out">导出</el-button>
out() {
out(this.select).then((res) => {
this.$downLoad("生日名单.xls", res);
});
},