前端下载后台接口返回的文件流

       Axios({
                method: "GET",
                url: url,
                headers: {
                    "Content-type": "application/json"
                },
                responseType: 'blob'
            }).then(res => {
                const blob = new Blob([res])
                const downloadElement = document.createElement('a');
                const href = window.URL.createObjectURL(blob); //创建下载的链接
                downloadElement.href = href;
                downloadElement.download = '自定义文件名.zip'; //下载后文件名
                document.body.appendChild(downloadElement);
                downloadElement.click(); //点击下载
                document.body.removeChild(downloadElement); //下载完成移除元素
                window.URL.revokeObjectURL(href); //释放掉blob对象

            }).catch(err => {
                message.warning("无点检数据")
            })
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容