一、使用插件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(_ => {}); },