下载附件时防止连点
作者:互联网
如果是button 直接加loading就能搞定
<el-button type="text" :loading="downLoading" @click="downloadFn(item)">下载</el-button>
如果是标签要加一个判断事件
<span v-loading="downLoading" class="downText" @click="downloadFn(item)">下载</span>
// 下载
async downloadFn(file) {
if (this.downLoading === false) {
this.downLoading = true
const res = await downloadFileByUniq(file.url)
this.downLoading = false
const blob = new Blob([res], { type: '' })
const downloadElement = document.createElement('a')
const href = window.URL.createObjectURL(blob)
downloadElement.href = href
downloadElement.download = this.$dayJs().format('YYYY-MM-DD HH:mm:ss') + file.name
document.body.appendChild(downloadElement)
downloadElement.click()
document.body.removeChild(downloadElement)
window.URL.revokeObjectURL(href)
}
},
标签:连点,downLoading,const,href,file,downloadElement,附件,document,下载 来源: https://www.cnblogs.com/hellofangfang/p/15543343.html