版权声明: https://blog.csdn.net/xiasohuai/article/details/83857921
get方式(3种写法):
1、window.open("**")是用新窗口打开URL页面
2、location.href="**"是用当前页面显示URL
window.open(this.GLOBAL.API_Spm_result+ "completionday/batchId/postId/export?batchId="+this.batchId+"&postId="+this.postId + '&access_token=' + sessionStorage.getItem('cookieaccess_token'))
window.location.href = this.GLOBAL.API_ACCOUNT + 'users/user/export?deptId=' + exportid + '&access_token=' + sessionStorage.getItem('cookieaccess_token')
download() {
//下载
var url = this.GLOBAL.API_ACCOUNT + 'users/download/user'
this.loading1 = true //下载中的动画提示
this.$get(url).then(res => {
if (res.data.retCode) {
alert(res.data.message)
} else {
window.location.href = url + '?access_token=' + sessionStorage.getItem('cookieaccess_token')
}
this.loading1 = false//下载中的动画提示隐藏
})
},
post方式(这里有两种方式 注释的是一种 js-file-download插件是一种的)
outputCompound(){
var url = this.GLOBAL.API_indicator + "indicator/composite/export"
var params = {
batchId:this.batchId,
objectType:"5"
}
axios.post(url,params,{responseType: 'arraybuffer'}).then((res) => {
// if(res.data.retCode){
// alert(res.data.message)
// }else{
// let blob = new Blob([res.data], {type: "application/vnd.ms-excel"});
// let objectUrl = URL.createObjectURL(blob);
// window.location.href = objectUrl;
//
//}
var fileDownload = require('js-file-download')
let fileName = "复合指标.csv";
fileDownload(res.data,fileName);
})
}