我需要通过vue-router
链接从远程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>
它可以工作,但我不想显示组件模板<template><div></div></template>
。我甚至不想刷新屏幕上的内容。有可能吗?
你不应该这样做。Vue组件已完成渲染。如果您不想呈现任何东西,那么作为mixin或插件,您的实现会更好。不过,我认为你可以做一些类似的事情:
render() {
return null;
},