AI智能
改变未来

用axios的post方式实现下载

钉钉、微博极速扩容黑科技,点击观看阿里云弹性计算年度发布会!>>>

亲测有效

dowloadTest(){this.$axios.request({method:\'post\',url:\'/api/filedue\',data:{fileid:123},responseType:\'arraybuffer\'}).then((response)=>{this.download(response.data);})},download (data) {if (!data) {return}let url = window.URL.createObjectURL(new Blob([data]))let link = document.createElement(\'a\')link.style.display = \'none\'link.href = urllink.download = \'ea7c0cf24153e0cd62bc8b64841fd84d.jpg\'; //下载后文件名link.setAttribute(\'download\', \'ea7c0cf24153e0cd62bc8b64841fd84d.jpg\')document.body.appendChild(link)link.click()}

后端返回文件流即可

赞(0) 打赏
未经允许不得转载:爱站程序员基地 » 用axios的post方式实现下载