在template模板里面写一个导出按钮
methods方法里面
//数据导出
export2Excel(
region1
) {
let param = this.$qs.stringify({
region1:region1,
offset:this.currentPage1,
limit:10
});
axios
.post("/api/business/car/downloadexcelpm",param)
.then(res => {
if (res.data.code == 200) {
console.log("导出成功!");
require.ensure([], () => {
const { export_json_to_excel } = require("@/Excel/Export2Excel");
const tHead = [
"拍卖日期",
"询价编号",
"保全日期",
"ID",
"平台费",
"实际费",
"停车费",
"拍次",
"停放地",
"保全人",
"登记日期",
"公司名称",
"车牌号",
"车辆型号",
"车架号",
"起拍价",
"保留价",
"成交价",
"当前价",
"保证金",
"加价幅度",
"综合服务费",
"合手价",
"中标人ID",
"中标人",
"中标人电话",
"客户类型",
"客服",
"客服电话",
]; // 对应表格输出的中文title
const filterVal = ["updateTime", "enquiryNo", "bqDate", "ID", "managenmentCost", "assistfee", "zk", "zk1", "place", "user_name", "firstTime", "name", "carNo", "brandNo", "vin", "auctionPrice", "reservePrice", "maxPrice", "currentPrice", "cashDeposit", "markUp", "Comprehensivefee", "hsj", "memberId", "memberName", "tele", "kind", "userName", "mobile"]; // 对应表格输出的数据
console.log(tHead);
const list = this.tableData;
const data = this.formatJson(filterVal, list);
/* eslint-disable */
export_json_to_excel(tHead, data, "拍卖会车辆统计列表");
});
} else {
console.log();
}
console.log(res);
})
.catch(function(error) {
console.log(error);
});
},
formatJson(filterVal, jsonData){
return jsonData.map(v => filterVal.map(j => v[j]));
},
通常导出数据传的参数和查询接口传的参数一样
然后写完方法记得在mounted里面调用这个方法
导出数据就是这样,下次写一个导入数据