【发布时间】:2019-05-24 08:59:30
【问题描述】:
vue中如何根据当前路由动态展示组件?
我只希望custom-component不在主页上可见。默认情况下,我将用户设置在主页上,因此组件在加载时不会显示。
我尝试了几种路由器方法都没有成功:https://router.vuejs.org/api/#router-instance-methods。
app.vue:
<template>
<div id="app" :class="$style.app">
<navbar/>
<custom-component v-bind:is="homePage"></custom-component>
<router-view :class="$style.content"/>
<footer/>
</div>
</template>
data() {
return {
homePage: true
}
},
methods: {
homePage() {
if(this.$route.path("/") || this.$route.path("/home")) {
this.homePage = true
} else {
this.homePage = false
}
}
}
这很接近,但没有达到预期的结果:VueJS - Load child components dynamically。
这也是我现在正在尝试在app.vue 中执行此操作的最佳方式。或者我应该在custom-component 中有这个逻辑吗?
【问题讨论】:
标签: vue.js