vue使用方法:
接口加上:
responseType: "arraybuffer",
export function postExport(data) { return request({ url: 'http。。。', method: 'POST', responseType: "arraybuffer",//加上这行 data }) }
页面里面:
let url = window.URL.createObjectURL( new Blob(['文件流'], { type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8", }) ); let link = document.createElement("a"); link.style.display = "none"; link.href = url; link.setAttribute("download", "比价文件"); document.body.appendChild(link); link.click(); document.body.removeChild(link); //下载完成移除元素 window.URL.revokeObjectURL(url); //释放掉blob对象
原生代码写:
window.location.href = "接口"+接口数据
window.location.href = "${ctx}/versionManagement/export?productDictCode=" +"&activityScheduleId="+value.id