-
解决方法:通过给a标签的click事件绑定一个函数来解决
<a @click="downloadFile(fileUrl, fileName)">点击下载</a>
> 函数如下
function downloadFile(url, fileName) {
var x = new XMLHttpRequest();
x.open('GET', url, true);
x.responseType = 'blob';
x.onload = function () {
var url = window.URL.createObjectURL(x.response);
var a = document.createElement('a');
a.href = url;
a.download = fileName;
a.click();
};
x.send();
}