提交 | 用户 | 时间
|
759b1c
|
1 |
export default { |
H |
2 |
// 下载 Excel 方法 |
|
3 |
excel(data, fileName) { |
|
4 |
this.download0(data, fileName, 'application/vnd.ms-excel'); |
|
5 |
}, |
|
6 |
|
|
7 |
// 下载 Word 方法 |
|
8 |
word(data, fileName) { |
|
9 |
this.download0(data, fileName, 'application/msword'); |
|
10 |
}, |
|
11 |
|
|
12 |
// 下载 Zip 方法 |
|
13 |
zip(data, fileName) { |
|
14 |
this.download0(data, fileName, 'application/zip'); |
|
15 |
}, |
|
16 |
|
|
17 |
// 下载 Html 方法 |
|
18 |
html(data, fileName) { |
|
19 |
this.download0(data, fileName, 'text/html'); |
|
20 |
}, |
|
21 |
|
|
22 |
// 下载 Markdown 方法 |
|
23 |
markdown(data, fileName) { |
|
24 |
this.download0(data, fileName, 'text/markdown'); |
|
25 |
}, |
|
26 |
|
|
27 |
download0(data, fileName, mineType) { |
|
28 |
// 创建 blob |
|
29 |
let blob = new Blob([data], {type: mineType}); |
|
30 |
// 创建 href 超链接,点击进行下载 |
|
31 |
window.URL = window.URL || window.webkitURL; |
|
32 |
let href = URL.createObjectURL(blob); |
|
33 |
let downA = document.createElement("a"); |
|
34 |
downA.href = href; |
|
35 |
downA.download = fileName; |
|
36 |
downA.click(); |
|
37 |
// 销毁超连接 |
|
38 |
window.URL.revokeObjectURL(href); |
|
39 |
}, |
|
40 |
|
|
41 |
} |