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' })
  • 相关阅读:
    c/c++(c++和网络编程)日常积累(二)
    docker日常积累
    c/c++日常积累
    qt日常积累
    YUV相关积累
    02-asio学习
    01--c实现基础客户端和服务端与c++ boost.asio实现对比
    webrtc学习笔记积累
    linux-日常工作积累
    用Java链接SQL Server
  • 原文地址:https://www.cnblogs.com/ruthless/p/9814493.html
Copyright © 2011-2022 走看看