gin端
"github.com/360EntSecGroup-Skylar/excelize/v2"
c.Header("response-type", "blob")
data, _ := file.WriteToBuffer()
c.Data(http.StatusOK, "application/vnd.ms-excel", data.Bytes())
vue端
axios.get("xxxx", {responseType: "blob"}).then(res => {
let blobUrl = window.URL.createObjectURL(new Blob([res.data], {
type: "application/vnd.ms-excel",
}))
const a = document.createElement("a");
a.style.display = "none";
a.download = "投放组合评估.xlsx";
a.href = blobUrl;
a.click();
});
重点 ****
vue端 ajax 里面必须存在{responseType: "blob"}