0
点赞
收藏
分享

微信扫一扫

vue如何下载文件

兮城 2022-02-01 阅读 247

一、使用axios请求后台接口

this.$http({
	url:'请求地址',
	method: 'post',
	responseType:'blob',
	data: data,
}).then(res => {
	this.downloadFile(res.data)  
})

二、下载

downloadFile(data) {
	// 文件导出
	if (!data) {
		return
	}
	let url = window.URL.createObjectURL(new Blob([data]));
	let link = document.createElement('a');
	link.style.display = 'none';
	link.href = url;
	link.setAttribute('download', '测试excel.xls');

	document.body.appendChild(link);
	link.click()
},
举报

相关推荐

0 条评论