vue中下载Excel模板文件


let fileName = '****';
downExcel(fileName).then(res => { // 请求下载接口
	// 处理返回的文件流
	const content = res;
	const blob = new Blob([content]);
	const fileName = "Excel文件名称" + ".xlsx";
	if ("download" in document.createElement("a")) {
		// 非IE下载
		const elink = document.createElement("a");
		elink.download = fileName;
		elink.style.display = "none";
		elink.href = URL.createObjectURL(blob);
		document.body.appendChild(elink);
		elink.click();
		URL.revokeObjectURL(elink.href); // 释放URL 对象
		document.body.removeChild(elink);
	} else {
		// IE10+下载
		navigator.msSaveBlob(blob, fileName);
	}
});

// 走后台接口 获取文件流
export function downExcel(fileName) { 
	return request({
		url:'**********?fileName=' + fileName,
                method:'get',
                headers: {
                    "Content-Type": "application/json;application/octet-stream"
                },
                responseType: "blob",
                params:''
	})
}

  

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM