使用了直接动态添加a标签的方法,还是会打开预览
let link = document.createElement('a');
link.style.display = 'none';
link.href = e.attachment;// https://sss.mulook.com/book/17956324022668224770/1.xlsx
document.body.appendChild(link);
link.click();
解决
let link = document.createElement('a')
let image = document.createElement('image')
let url = e.attachment
let downloadName = url.slice(url.lastIndexOf("/") + 1)
console.log(url, downloadName);
// 这里是将url转成blob地址,
image.setAttribute("crossOrigin", "anonymous") // 这句可以解决跨域问题
fetch(url).then(res => res.blob()).then(blob => { // 将链接地址字符内容转变成blob地址
link.href = URL.createObjectURL(blob)
// console.log(link.href)
link.download = downloadName
document.body.appendChild(link)
link.click()
})