API文件中:
let headers = { ∵
CLIENT_SYS_CODE:“prscfg” J
}
export function downloaExcel (data) {
return request ({
url:“ /downloadExcel”,
method: “post”,
responseType:“blob”, (如果一直联调不成功注意这里)
headers: headers (看后端需求,可加可不加)
组件中:
exportprd (){
let formdata = {
入参
}
downloaExcel(formdata).then ((resp) => {
let content = resp.data
let a = document.createElement(“a”)
a.download = “模版.xlsx”
a.style.display = “none”
let blob = new Blob ([content], {type: application/octet- stream})
a.href = URL.createObjectURL(blob)
document.body.appendChild(a)
a.click()
document.body.removeChild(a)
})