vue下载静态资源js
import axios from 'axios'export default function fileDownLoad(path) {let urls = path.split('/');axios.create().get(path,{responseType: 'blob'}).then(res => {l...
·
import axios from 'axios'
export default function fileDownLoad(path) {
let urls = path.split('/');
axios.create().get(path,{
responseType: 'blob'
}).then(res => {
let blob = new Blob([res.data],{type:'application/download'});
let objectUrl = URL.createObjectURL(blob);
let a = document.createElement('a');
a.download = urls[urls.length-1];
a.href = objectUrl;
a.click();
}
).catch(e => {
return e;
})
}
更多推荐
已为社区贡献3条内容
所有评论(0)