ElementUI 导出、下载功能


一、使用插件qs进行参数序列化

1、安装

qs可通过npm install qs --save命令进行安装,是一个npm仓库所管理的包。

2、引入

import Qs from "qs";

3、qs主要有2个方法

方法一:qs.stringify():将对象序列化成URL的形式,多个对象之间用&拼接(拼接是由底层处理,无需手动操作)

 

var a = {name:'hehe',age:10};
qs.stringify(a)
// 'name=hehe&age=10'
JSON.stringify(a)
// '{"name":"hehe","age":10}'

 

方法二:qs.parse():将序列化的内容拆分成一个个单一的对象

let a = 'name=hehe&age=10';
console.log(Qs.parse(a));  
//{name: "hehe", age: "10"}

 

二、导出方法

exportHandle() {
      const that = this;
      if (null == that.tableData || that.tableData.length == 0) {
        that.$message.error("暂时没有批量导出的数据");
        return;
      }
      let param = {
        startTime: that.deviceFormData.time[0],
        endTime: that.deviceFormData.time[1],
        unitId: that.deviceFormData.unitId,
      };
      let queryStr = Qs.stringify(param);
      let url = ApiConfig.linkAdress + ApiConfig.api["monitorAccidentInfoForExcel"] + "?" + queryStr;
      that.$confirm("确认批量导出excel?", "导出提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
        .then(_ => {
          window.open(url);
        })
        .catch(_ => {});
    },

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM