1. 单个附件下载文章来源:https://www.toymoban.com/news/detail-709579.html
<el-button
type="text"
size="small"
@click.native.prevent="download(scope.row)" >下载</el-button>
export default {
data() {
return {
downloadUrl: 'http://127.0.0.1:8881/XX/XX', // 下载接口
}
},
methods: {
download(row) { // 单个附件下载
// 下载附件(form方式)
const params = {
fileId: row.dataId,
fileName: row.fileName,
attachmentId: row.dataId,
token: getToken()
}
this.postDownloadFile(params, this.downloadUrl)
// downloadFileByToken({ attachmentId: row.dataId }).then((response) => { // 按钮提交无效
// })
},
postDownloadFile(params, url) {
const form = document.createElement('form')
form.style.display = 'none'
form.action = url
form.method = 'post'
document.body.appendChild(form)
// 动态创建input并给value赋值
for (const key in params) {
const input = document.createElement('input')
input.type = 'hidden'
input.name = key
input.value = params[key]
form.appendChild(input)
}
form.submit()
form.remove()
},
},
}
灵感来自:https://blog.csdn.net/ewl0116/article/details/129879216文章来源地址https://www.toymoban.com/news/detail-709579.html
到了这里,关于element-ui文件下载(单个)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!