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

相关推荐
ndsc_d14 小时前
AI生成的UI如何继续修改?画布内生成与独立AI设计工具比较
人工智能·ui·ai·ui设计·ai设计·ai设计工具·ai生成ui
理想三旬(づ ̄3 ̄)づ╭~18 小时前
深入理解 AG-UI 协议:Agent 与前端实时交互的底层原理
ui
爬楼的猪18 小时前
一个轻量化的Codex Web UI
人工智能·ui·chatgpt·ai编程
copilot中国版2 天前
Outlook Copilot|客户沟通
ui·copilot·outlook
Cx330❀2 天前
Qt 界面美化指南:从零掌握 QSS 核心机制与工程实践
开发语言·qt·ui·性能优化·图形渲染
兰亭妙微UI设计公司2 天前
兰亭妙微ui咨询公司分享:设计原则及组件详解
ui
兰亭妙微UI设计公司2 天前
兰亭妙微界面设计公司分享:DeepSeek AI智能助手应用UI/UX设计深度解析
人工智能·ui·ux
沫璃染墨2 天前
《Qt从零入门系列(十三):QSS样式表详解——从选择器与层叠规则到控件美化实战》
开发语言·css·c++·qt·ui·qt6.3·qss
WarPigs3 天前
UI路径配置SO>字典json工作流
ui·unity
stevenzqzq3 天前
mvi理解2-ui状态和业务状态
ui