vue中点击下载
1、template中代码片段
<el-table-column fixed="right" label="" width="100">
<template slot-scope="scope">
<el-button
type="text"
size="small"
@click="handleDownd(scope.row)"
>下载
</el-button>
</template>
</el-table-column>
2、js代码
// 点击下载
handleDownd(rowItem) {
const params = {
realFileName: rowItem.fileRealName
}
StrategyDownd(params).then(res => {
const link = document.createElement('a')
link.download = '批量模板.xls'//所下载的文件名称,此为自定义属性
link.style.display = 'none'
link.href = window.URL.createObjectURL(res)
document.body.appendChild(link)
link.click()
window.URL.revokeObjectURL(link.href) // 释放URL 对象
document.body.removeChild(link)
})
},
// 下载
export function StrategyDownd(params) {
return request({
url: `${MODULE_URL}/signal/file`,
method: 'get',
params,
responseType: 'blob'
})
}