vue-axios 下载 zip文件包

两盒软妹~` 提交于 2020-02-20 13:31:05
axios({
                method: 'get',
                url: '/api/group/export',
                params: data,
                headers: {
                    Authentication: localStorage.getItem('token'),
                    Accept: 'application/vnd.openxmlformats-officedocument'
                },
                responseType: 'blob'
            }).then(response => {
                console.log(response.data);
                
                const blob = new Blob([response.data], {type: 'application/zip'});
                const filename = response.headers['content-disposition'];
                const downloadElement = document.createElement('a');
                const href = window.URL.createObjectURL(blob); //创建下载的链接
                console.log(href);
                
                downloadElement.href = href;
                [downloadElement.download] = [filename.split('=')[1]];
                document.body.appendChild(downloadElement);
                downloadElement.click(); //点击下载
                document.body.removeChild(downloadElement); //下载完成移除元素
                window.URL.revokeObjectURL(href); //释放blob对象
            }).catch((error) => {

            })

  

axios({
                method: 'get',
                url: '/api/group/export',
                params: data,
                headers: {
                    Authentication: localStorage.getItem('token'),
                    Accept: 'application/vnd.openxmlformats-officedocument'
                },
                responseType: 'blob'
            }).then(response => {
                console.log(response.data);
                
                const blob = new Blob([response.data], {type: 'application/zip'});
                const filename = response.headers['content-disposition'];
                const downloadElement = document.createElement('a');
                const href = window.URL.createObjectURL(blob); //创建下载的链接
                console.log(href);
                
                downloadElement.href = href;
                [downloadElement.download] = [filename.split('=')[1]];
                document.body.appendChild(downloadElement);
                downloadElement.click(); //点击下载
                document.body.removeChild(downloadElement); //下载完成移除元素
                window.URL.revokeObjectURL(href); //释放blob对象
            }).catch((error=> {

            })
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!