当前位置: 首页 > news >正文

vue3 excel 文件导出

//文件导出  在index.ts 中

export function downloadHandle(url: string,params?:object, filename?: string, method: string = 'GET'){

    try {

        downloadLoadingInstance = ElLoading.service({

            text: "正在生成下载数据,请稍候",

            background: "rgba(0, 0, 0, 0.7)",

        });

        return service.get(url, {

            responseType: 'blob',

            params:params?params:''

        }).then(async (resp: any) => {

            // 创建a标签

            const down = document.createElement('a')

            // 文件名没传,则使用时间戳

            if (filename) {

                down.download = filename

            } else {

                const downName = resp.headers['content-disposition'].split('=')[1]

                down.download = decodeURI(downName)

            }

            // 隐藏a标签

            down.style.display = 'none'

            // 创建下载url

            down.href = URL.createObjectURL(

                new Blob([resp.data], {

                    type: resp.data.type

                })

            )

            // 模拟点击下载

            document.body.appendChild(down)

            down.click()

            // 释放URL

            URL.revokeObjectURL(down.href)

            // 下载完成移除

            document.body.removeChild(down)

            downloadLoadingInstance.close();

        }).catch((r: any) => {

            console.error(r);

            ElMessage.error('下载文件出现错误,请联系管理员!');

            downloadLoadingInstance.close();

        });

    } catch (err: any) {

        ElMessage.error(err.message)

    }

}

在页面中 引入

import {downloadHandle} from "../../api/index";

const downloadFun = () => {

    downloadHandle("/bg/customer/accountQuantity/exportExcelTemplate");

};

http://www.lryc.cn/news/356017.html

相关文章:

  • 优雅的代码规范
  • JVM、JRE 和 JDK 的区别,及如何解决学习中可能会遇到的问题
  • 【开源】加油站管理系统 JAVA+Vue.js+SpringBoot+MySQL
  • 详解 Scala 的泛型
  • 【本周面试问题总结】
  • SaltStack
  • 【Rust日报】Rust 中的形式验证
  • vue3项目中新增修改时使用nextTick时遇到的问题
  • 算法训练 | 二叉树Part7 | 530.二叉搜索树的最小绝对差、501.二叉搜索树中的众数
  • C++面向对象程序设计 - 标准输出流
  • 警惕Mallox勒索病毒的最新变种hmallox,您需要知道的预防和恢复方法。
  • 2024年华为OD机试真题-火星文计算-C++-OD统一考试(C卷D卷)
  • 3.00001 postgres如何初始化系统参数?
  • C# 读取 CSV 文件的方法汇总
  • element+ 引入图标报错 Failed to resolve import “@element-plus/icons-vue“ from “
  • Github 2024-05-25 开源项目日报 Top10
  • VPN的详细理解
  • java后端轮播图的设计
  • upload-labs 21关解析
  • 常用汇编指令
  • LabVIEW软件需求分析文档内容和编写指南
  • spring cache(三)demo
  • Android 应用开发语言选择对比
  • Git 小白入门到进阶—(基本概念和常用命令)
  • 大数据框架总结(全)
  • 44、Flink 的 Interval Join 详解
  • H6246 60V降压3.3V稳压芯片 60V降压5V稳压芯片IC 60V降压12V稳压芯片
  • 【MySQL精通之路】查询优化器的使用(8)
  • Docker in Docker(DinD)原理与实践
  • 科技前沿:IDEA插件Translation v3.6 带来革命性更新,翻译和发音更智能!