通过“流”,在浏览器上直接下载文件

①生成文件。
请求后端接口,后端返回流,前端构造相应的url,
window.open(url)

downloadTable() {
    let param = {
        data1: data1,
        data2: data2
    };
    this.post({
        url: 'blServer/getServerData/',
        module: 'activiti',
        version: '0_2_0',
        data: param,
        onload: res => {
            let url =
                '/module/api/interface/?' +
                'time=' + new Date().getTime() +'&' +
                'number=' + formId;
            window.open(url);
        }
    })
}
② 请求数据库里现有文件。
直接构造url,window.open打开
downloadFile() { let fileName
= 'xxx.xls'; let fileRealName = 'xxx.xls'; let url = this.apiman('module', 'interface'); //下载url let param = this.axios.param({ file_name: fileName, file_real_name: fileRealName },true); param = 'action=' + JSON.stringify(param.action) + '&auth=' + JSON.stringify(param.auth); url = url + '?' + param; window.open(url); }

 

posted @ 2019-08-16 15:43  一个一  阅读(1981)  评论(0)    收藏  举报