1. 新建js文件:blob-url.js
/**
* blob to download
**/
export function download(target, downloadName) {
let url = '';
if (target instanceof Blob) {
url = blobToURL(target);
} else if (typeof target === 'string') {
url = target;
}
if (url) {
let a = document.createElement('a');
a.href = url.url || url;
a.download = downloadName || '';
a.click();
if (url.revokeFn) url.revokeFn();
a = null;
}
}
2. 引入主页并且使用:
import { download } from "@/utils/blob-url";
<button class="btn-blue-fill"
@click="outputTable" style="float: left;">下载Excel模板
</button>
outputTable() {
download(接口返回路径, `定向操作资金模板.xls`);
},