vue axios如何写excel导出
this.$http.post(global.domain + '/goodsRecord/export',{keyword:this.goodsName,supplier_id:this.supplier_id,condition:this.condition,...
·
this.$http.post(global.domain + '/goodsRecord/export',{
keyword:this.goodsName,
supplier_id:this.supplier_id,
condition:this.condition,
sort:this.sort,
},{responseType: 'arraybuffer'}).then((res) => {
let fileName = '商品上架总览.xls'
let blob = new Blob([res.data], { type: 'application/x-xls' })
if (window.navigator.msSaveOrOpenBlob) {
navigator.msSaveBlob(blob, fileName);
} else {
var link = document.createElement('a');
link.href = window.URL.createObjectURL(blob);
link.download = fileName;
link.click();
window.URL.revokeObjectURL(link.href);
}
})
一定要记得加axios的第三个参数哦
{responseType: 'arraybuffer'} //{responseType: 'blob'}也行哦
不然就会乱码
更多推荐
已为社区贡献11条内容
所有评论(0)