两种方式下载:
第一种:直接a标签下载
<a class="item-btn download" :href="'/xxx/xxx/download?id=' + xxx.id" :download="xxx.name">下载附件</a>
第二种:
<el-button class="item-btn download" @click="downloadEnclosure(fileUrl, fileName)">下载附件</el-button>
// 下载附件 async downloadEnclosure(url, name) { let response = await fetch(url) let blob = await response.blob() let objectUrl = window.URL.createObjectURL(blob) let a = document.createElement('a') a.href = objectUrl a.download = name a.click() a.remove() },
注: a标签通过js创建的方式:
handleClick(item){ const fileUrl = `/xxx/xxx/download?id=${item.id}` const link = document.createElement('a') link.className = 'download_btn' link.href = fileUrl link.setAttribute('download',item.name) link.click() link.remove() }
标签:vue,item,download,link,附件,let,下载 From: https://www.cnblogs.com/anna001/p/17887041.html