element-ui文件下载(单个)

  1. 单个附件下载
javascript 复制代码
<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

相关推荐
陈言必行2 小时前
Unity 实战:屏蔽移动平台 UI 点击检测的“坑”与解决之道
ui·unity·游戏引擎
特立独行的猫a2 小时前
cpp-linenoise介绍——让命令行拥有猫一般的敏捷
c++·ui·命令行·cpp-linenoise
Emma_Maria1 天前
关于vant-ui-vue 的datepicker 时间选择错乱问题的处理
前端·vue.js·ui
BW.SU1 天前
RUI Builder-图形化UI设计-工程范例
stm32·单片机·嵌入式硬件·ui·界面设计·单片机驱动彩屏·ra8889
Devlab1 天前
anyui - Master designer for LVGL [New release v0.40.0]
嵌入式硬件·物联网·低代码·ui·iot
小新1102 天前
vs2022+Qt插件初体验,创建带 UI 界面的 Qt 项目
开发语言·qt·ui
北极糊的狐2 天前
三星 One UI 8 停止支持 三星Dex后的替代指南
ui
狮智先生2 天前
【编程实践】Windows + PySide6 + Matplotlib 绘图时 WinError 32 的完整排查与解决方案
windows·ui·个人开发·matplotlib·交通物流
starrycode8882 天前
【每日一个知识点】Kotlin开发基础知识
ui·kotlin
企微自动化2 天前
企业微信客户端 UI 自动化定位技术的稳定性和局限性
ui·自动化·企业微信