在http.js文件夹中:
export function downFile(url, data, filename) {
axios.post(url, data, { responseType: 'blob' })
.then(data => {
let blob = new Blob([data.data]);
console.log(data);
let url = window.URL.createObjectURL(blob);
let link = document.createElement('a');
link.style.display = 'none';
link.href = url;
link.setAttribute('download', filename);
document.body.appendChild(link);
link.click();
window.URL.revokeObjectURL(url);
document.body.removeChild(link);
});
}
导出: 1.import {downFile} from "@/utils/http.js"
2.在method中:
methods: {
//导出
export_but(){
downFile('/XXX/XXXXXXXX', {
topicSetId: '3',
userGroupId: '3'//给后端返回值
}, 'file.xls');
},
'/XXX/XXXXXXXX'后端接口
|