vue 流的方式下载文件

获取到流后

downloadFn(){
    
    
	// res.data返回的流
	const blob = new Blob([res.data],{
    
    type:'application/octet-stream'});
	const fileName = '导出文件.zip';
	const Url = window.URL|| window.webkitURL;
	if('download' in document.createElement('a')){
    
     //非ie下载
		const elink = document.createElement('a');
		elink.download = download;
		elink.style.display = 'none';
		elink.href = URL.createObjectURL(blob);
		document.body.appendChild(elink);
		elink.click();
		URL.revokeObjectURL(elink.href);
		document.body.removeChild(elink);
	}else {
    
     // ie10下载
		navigator.msSaveBlob(blob,download)
	}
}

猜你喜欢

转载自blog.csdn.net/weixin_43979503/article/details/125547560