vue 文件下载(需调用接口)
发布时间:2020-12-16 23:11:33 所属栏目:百科 来源:网络整理
导读:methods:{ // 下载文件 filerightDown(index,fileName) { // index 接口参数 fileName文件名字 var _this = this ; var fileName = fileName; this .$http({ method: "post" ,url: this .HOST + api.download,params: { fileId: index },responseType: 'arra
methods:{ //下载文件 filerightDown(index,fileName) {//index 接口参数 fileName文件名字 var _this = this; var fileName = fileName; this.$http({ method: "post",url: this.HOST + api.download,params: { fileId: index },responseType:'arraybuffer' }) .then(res => { this.download(res.data,fileName); }) .catch(req => { console.log("下载失败",req); }); },// 下载文件 download (data,fileName) { if (!data) { return } let url = window.URL.createObjectURL(new Blob([data])); let link = document.createElement('a'); link.style.display = 'none'; link.href = url; link.setAttribute('download',fileName); document.body.appendChild(link); link.click(); },} ? responseType:'arraybuffer'
new Blob ? (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |