zoukankan      html  css  js  c++  java
  • post请求导出Excel表格

    axios.interceptors.response.use((response) =>{
    if(response.config && response.config.responseType == 'blob') {
    const blob = new Blob([response.data], { type: 'application/x-msdownload' }); //后台需要相同的type
    let filename = `${name}.xls`;
    if ('download' in document.createElement('a')) {
    const downloadElement = document.createElement('a');
    let href = '';
    if(window.URL) href = window.URL.createObjectURL(blob);
    else href = window.webkitURL.createObjectURL(blob);
    downloadElement.href = href;
    downloadElement.download = filename;
    document.body.appendChild(downloadElement);
    downloadElement.click();
    if(window.URL) window.URL.revokeObjectURL(href);
    else window.webkitURL.revokeObjectURL(href);
    document.body.removeChild(downloadElement);
    } else {
    navigator.msSaveBlob(blob, filename);
    }
    return Promise.resolve(response.data);
    }
    return response;
    })
    
    
    const defaultConfig = {
    baseURL: '',
    mode: 'cors',
    headers: {
    // "your-content": 'application/x-msdownload',
    "Accept": "application/json",
    "Content-Type": "application/json;charset=utf-8"
    },
    responseType: 'json'
    }
    
    
    const post2 = (url, data, config) => {
    return axios.post(url, data, Object.assign({}, defaultConfig, config))
    }
    
    
    https.post2(this.apiName.exportMealGroupByDateAndShop,data,{ responseType: 'blob' })
  • 相关阅读:
    文件下载并删除
    程序输出
    什么是并发
    跨站脚本攻击为什么要过滤危险字符串
    正则表达式——极速入门
    输出的为X= 1 ,Y = 0;
    Eclipse+MyEclipse安装及环境配置
    J2EE有三个开发环境级。
    TCP和UDP的区别
    asp.net2.0导出pdf文件完美解决方案(转载)
  • 原文地址:https://www.cnblogs.com/ruthless/p/9814493.html
Copyright © 2011-2022 走看看