美文网首页
2023-02-28 金刚导出方法

2023-02-28 金刚导出方法

作者: 流泪手心_521 | 来源:发表于2023-02-27 10:09 被阅读0次

    //{ responseType:'blob',}注意一定要跟参数分开写,否则导出的excel打不开


    image.png
    
    http.get('/expressDetail/exportData',{
                        customerCode:this.listForm.customerCode,
                        jpOrgCodes:this.listForm.jpOrgCodes,
                        outStockTime:this.listForm.outStockTime,                
                    },{  responseType:'blob',}
                    ).then(response => {
                        this.exportLoading=false
                        const blob = new Blob([response], {
                            type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8"
                        });
                        let fileName='集配快递费'+ moment().format('YYYYMMDD HHmmss')
                        if (
                            "download" in document.createElement("a") &&
                            navigator.userAgent.indexOf("Edge") <= -1
                        ) {
                            // 非IE 及edge下载
                            const elink = document.createElement("a");
                            elink.download = fileName;
                            elink.style.display = "none";
                            elink.href = URL.createObjectURL(blob);
                            document.body.appendChild(elink);
                            elink.click();
                            URL.revokeObjectURL(elink.href);
                            document.body.removeChild(elink);
                        } else {
                            // IE10+下载
                            navigator.msSaveOrOpenBlob(blob, fileName);
                        }
                    }).catch(function (error) {
                        console.log('error: ', error);
                    });
    
    

    相关文章

      网友评论

          本文标题:2023-02-28 金刚导出方法

          本文链接:https://www.haomeiwen.com/subject/mkehldtx.html