1. //导出
exportFn: function(){
//下载导出模板
$('#download').click(function(){
window.open('/api/houses/house-model-export');
})
//导出列表
$('#export_list').click(function(){
window.open('/api/houses/house-hold-export/' + _id);
})
},
2. 创建标签
var paramsL = Object.keys(params).map(function (key) {
return encodeURIComponent(key) + "=" + encodeURIComponent(params[key]);
}).join("&");
this.downLoadFile('/api/bank/export?'+paramsL) //调用
downLoadFile(url){
const a = document.createElement('a'); // 创建a标签
a.href = url
//a.click();// 自执行点击事件 火狐有兼容性问题
var evt = document.createEvent("MouseEvents");
evt.initEvent("click",true,true);
a.dispatchEvent(evt);
},
调用:this.downLoadFile('/api/bank/fileDownload') //url是后台给我地址链接
像接口获取数据的时候:数据放在data中和放在pramas中是不一样的