zoukankan      html  css  js  c++  java
  • formData文件下载

    //创建内存中的表单对象

    var form = new FormData();
    //向其中添加要传输的数据
    form.append("参数名", 参数值);
     
    axios.post(downloadUrl, form
    , { responseType: 'blob'
    }).then(res => {
       let blob = res.data 
       let reader = new FileReader()
       reader.readAsDataURL(blob)
       reader.onload = (e) => {
       let a = document.createElement('a')
       a.download = '文件名'
       a.href = e.target.result
       document.body.appendChild(a)
       a.click()
       document.body.removeChild(a) }
    })
     
     
     
     
    //////////////////////////////////////////////////////////////////////////////////////////////////第二种写法
     this.httpclient.request('POST', url, {
                responseType: 'blob',
                params: new HttpParams({
                    fromObject: requestParam //传入的参数对象
                }),
                body: requestParam
            }).toPromise().then((val) => {
                //   从后台查询到数据后进行导出最后的操作
                const blob = new Blob([val], { type: 'application/vnd.ms-excel' });
                const fileName = curFileName + '.xls';
                if (window.navigator.msSaveOrOpenBlob) {// For IE浏览器
                    navigator.msSaveBlob(blob, fileName);
                } else { // For 其他浏览器
                    const objectUrl = URL.createObjectURL(blob);
                    const a = document.createElement('a');
                    document.body.appendChild(a);
                    a.setAttribute('style', 'display:none');
                    a.setAttribute('href', objectUrl);
                    a.setAttribute('download', fileName);
                    a.click();
                    URL.revokeObjectURL(objectUrl);
                }
            } 
  • 相关阅读:
    给Debian安装Xfce桌面
    【兄弟连ThinkPHP】1、介绍和安装
    CROSS JOIN,NATURAL JOIN
    表的连接查询
    多表查询在数据量非常大的时候性能不好,慎用!
    伪列:Oracle显示查询结果前几条记录用rownum<=。去掉重复记录,保留最早录入记录:取出最小ROWID
    其他函数:值为NULL时的默认值NVL,DECODE
    转换函数TO_CHAR,TO_DATE,TO_NUMBER
    50-用Python监听鼠标和键盘事件
    49-Python 安装pythoncom库和pyHook
  • 原文地址:https://www.cnblogs.com/cs122/p/9665043.html
Copyright © 2011-2022 走看看