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"}

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐