1.?單個(gè)附件下載文章來源:http://www.zghlxwxcb.cn/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) { // 單個(gè)附件下載
// 下載附件(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)
// 動態(tài)創(chuàng)建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文章來源地址http://www.zghlxwxcb.cn/news/detail-709579.html
到了這里,關(guān)于element-ui文件下載(單個(gè))的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!