1.接口封装
export const getExcle = async (data)=>{
return await request.post ({
url:"" //接口路径,
data,
responseType:"blob,
})
}
2.调用接口
const getExcleFun = ()=>{
getExcle({
参数
}).then((res)=>{
let content =res
let a = document.creareElement("a”)
a.style.display = none
a.download = "文件名.xlsx"
let blob = new Blob([content])
a.href = URL.createObjectURL(blob)
document.body.appendChild(a)
a.click()
document.body.removeChild(a)
})
}