vue2实现后台管理系统导出文件并进行下载

本文介绍如何在Vue2的后台管理系统中实现文件的导出和下载功能。通过在src/utils创建common.js模块,并在main.js中全局注册,以便在应用中调用this.$common进行文件操作。
摘要由CSDN通过智能技术生成
 <el-button
            type="danger"
            @click="expot"
            icon="el-icon-download"
            v-permission="'merchants:enter:tenant:export'"
            >导出</el-button
          >
// 导出excel表
      expor(where) {
        console.log(where, '导出elcel表');
        this.req
          .get('后端接口', {
            params: where,//可以进行搜索条件帅选出来下载
            deep: true,
            responseType: 'blob'
          })
          .then((res) => {
            this.$common.downFile(res);//这个this.$common是一个js文件,之后全局挂载
          });
      },

在src下面utils下面新建一个common.js

export default {
  downFile(octetStream) {
    let blob = new Blob([octetStream.data], {
      type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8'
    });
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值