效果:一点击超链接实现下载功能
直接代码:
<a @click="downlad(defaultconfig.requestApi + guide, fileName)">
<div class="downImg"><img :src="downImg" /></div>
<div class="alt" :title="fileName">{{ fileName }}</div>
</a>
方法:
const downlad = (url: any, fileName: any) => {
const newUrl = url;
const x = new XMLHttpRequest();
x.open("GET", newUrl, true);
x.responseType = "blob";
x.onload = () => {
const url = URL.createObjectURL(x.response);
const a = document.createElement("a");
a.href = url;
a.download = fileName;
a.target = "_blank";
a.click();
};
x.send();
};