Vuejs2 如何通过vue路由器链接从远程api下载base64文件?
我需要通过Vuejs2 如何通过vue路由器链接从远程api下载base64文件?,vuejs2,Vuejs2,我需要通过vue路由器链接从远程api下载文件。远程api返回base64中的文件 我添加路线: const router = new VueRouter({ mode: 'history', routes: [ { path: '/files/:id', name: 'file', component: Vue.component('vue-file'), props: true } ], }); 并为其添加组件: <template>
vue路由器
链接从远程api下载文件。远程api返回base64
中的文件
我添加路线:
const router = new VueRouter({
mode: 'history',
routes: [
{ path: '/files/:id', name: 'file', component: Vue.component('vue-file'), props: true }
],
});
并为其添加组件:
<template>
<div>
</div>
</template>
<script>
export default {
name: 'file',
props: {
id: String
},
mounted: function() {
this.download();
},
methods: {
download: function() {
let $this = this;
axios
.get('apiurl' + encodeURIComponent(this.id))
.then(function (response) {
download(response.data.base64content)
});
}
}
}
</script>
导出默认值{
名称:'文件',
道具:{
id:字符串
},
挂载:函数(){
下载();
},
方法:{
下载:函数(){
让$this=this;
axios
.get('apirl'+encodeURIComponent(this.id))
.然后(功能(响应){
下载(response.data.base64content)
});
}
}
}
它可以工作,但我不想显示组件模板
。我甚至不想刷新屏幕上的内容。可能吗?你不应该。Vue组件已完成渲染。如果您不想呈现任何内容,那么作为mixin或插件,您的实现会更好。
尽管如此,我认为你可以这样做:
render() {
return null;
},