zoukankan      html  css  js  c++  java
  • vue 用axios实现调用接口下载excel(一定要指定类型为二进制流)

     

    
    
    import axios from 'axios'
    exportExcel () {
            let url = 'http...',
            axios.get(url, {
                headers:{
                    "Admin_token":token
                },
                responseType: 'blob', //二进制流
            }).then(function (res) {
                if(!res) return
                let blob = new Blob([res.data], {type: 'application/vnd.ms-excel;charset=utf-8'})
                let url = window.URL.createObjectURL(blob);
                let aLink = document.createElement("a");
                aLink.style.display = "none";
                aLink.href = url;
                aLink.setAttribute("download", "excel.xls");
                document.body.appendChild(aLink);
                aLink.click();
                document.body.removeChild(aLink); 
                window.URL.revokeObjectURL(url); 
            }).catch(function (error) {
                console.log(error)
            });
        }
  • 相关阅读:
    MFC列表控件更改一行的字体颜色
    MFC之sqlite
    MFC笔记10
    MFC---关于string.h相关函数
    MFC笔记8
    MFC笔记7
    MFC笔记6
    MFC笔记5
    MFC笔记4
    MFC笔记3
  • 原文地址:https://www.cnblogs.com/shun1015/p/12580815.html
Copyright © 2011-2022 走看看