效果图:
html代码
<el-button class="btn_default" type="primary" style="background-color: #0075c2;width:5vw"
@click="downloadTemplate">
<template #icon>
<span class="btn-text">模板下载</span>
</template>
</el-button>
js代码
const downloadTempFile = () => {
let param = {
route: '/warehouseManage/inventorySet',
indexCode: '1'
}
return new Promise((resolve, reject) => {
downloadTemplateFile(param).then(res => {
if (res.data.code == '0') {
const eleLink = document.createElement('a')
eleLink.download = 'xxxx.xlsx'
eleLink.style.display = 'none'
eleLink.href = res.data.data
document.body.appendChild(eleLink)
eleLink.click()
document.body.removeChild(eleLink)
} else {
ElMessage.warning(`下载失败,${res.data.message}`)
}
resolve(true)
}).catch(err => {
ElMessage.warning(`下载失败,${res.data.message}`)
reject(false)
})
})
}