黑豹程序员-vue3下载文件

原理

vue3利用在页面中动态创建a标签,设置a标签属性,触发a标签的click实现文件下载。

代码

在前端工程的public资源目录下,创建template模板文件目录,把要下周的模板文件放入:product-dir.xlsx

        <el-button type="warning" size="small" @click="fileDownload(`/template/product-dir.xlsx`)">
          <el-icon><Document /></el-icon>&nbsp;模板下载
        </el-button>
const fileDownload = (url) => {
   
  //url:下载文件的url
  const a = document.createElement('a')
  a.setAttribute('download', '产品目录模板.xlsx')
  a.setAttribute('target', '_blank')
  a.setAttribute('href', url)
  a.click()
}

相关推荐

  1. 黑豹程序员-vue3下载文件

    2023-12-29 21:26:03       62 阅读
  2. vue3 blob下载文件

    2023-12-29 21:26:03       39 阅读
  3. vue3下载base64文件

    2023-12-29 21:26:03       26 阅读
  4. vue3 项目中 前端实现下载模板 csv文件

    2023-12-29 21:26:03       24 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2023-12-29 21:26:03       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2023-12-29 21:26:03       106 阅读
  3. 在Django里面运行非项目文件

    2023-12-29 21:26:03       87 阅读
  4. Python语言-面向对象

    2023-12-29 21:26:03       96 阅读

热门阅读

  1. 清理 Oracle Arch 目录中的日志文件

    2023-12-29 21:26:03       56 阅读
  2. Oracle exists和in的效率问题

    2023-12-29 21:26:03       50 阅读
  3. Go 正则匹配之跨行匹配

    2023-12-29 21:26:03       54 阅读
  4. Linux 查看网络命令 netstat 详解

    2023-12-29 21:26:03       46 阅读
  5. Python 爬虫 教程

    2023-12-29 21:26:03       55 阅读
  6. 由js文件中引入另外的js文件想到的

    2023-12-29 21:26:03       60 阅读
  7. Linux的中断响应流程是什么

    2023-12-29 21:26:03       59 阅读
  8. Unity 关于json数据的解析方式(LitJson.dll插件)

    2023-12-29 21:26:03       56 阅读
  9. PageHelper 使用示例

    2023-12-29 21:26:03       58 阅读