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)
            });
        }
  • 相关阅读:
    String
    Map和Set
    js的栈与堆
    js的私有属性
    随便谈一谈原型
    前端页面优化提速
    nth-child和nth-of-type
    重复输出字符串
    闭包
    mongodb内嵌文档的查询
  • 原文地址:https://www.cnblogs.com/shun1015/p/12580815.html
Copyright © 2011-2022 走看看