根据NUXT中当前路径的切换组件切换
我的布局/default.vue
看起来像这样:
<template>
<v-app style="background-color: transparent; color: unset">
<v-main>
<ActHeader></ActHeader>
<Nuxt
v-if="
!$nuxt.isOffline ||
$route.name == 'profile-downloads' ||
$route.name == 'profile-downloads-id'
"
style="min-height: 300px"
/>
<Footer />
</v-main>
</v-app>
</template>
<script>
import Footer from '@/components/Footer.vue'
export default {
components: {
Footer,
},
async fetch() {
await this.$store.dispatch('store/retrieveSettings')
await this.$store.dispatch('store/retrieveMenus')
},
}
</script>
我不想显示actheader
和footer
comptents components 到第一页(> /
),但是在其他页面(about
)中,我想显示这些组件。
我已经知道发现URL并使用这样的手表:
watch: {
$route (to, from) {
//false actHeader and Footer Components!
}
}
实际上它在工作,但是我正在寻找一个更好的答案,也许是更合乎逻辑的答案。
My layouts/default.vue
looks like this:
<template>
<v-app style="background-color: transparent; color: unset">
<v-main>
<ActHeader></ActHeader>
<Nuxt
v-if="
!$nuxt.isOffline ||
$route.name == 'profile-downloads' ||
$route.name == 'profile-downloads-id'
"
style="min-height: 300px"
/>
<Footer />
</v-main>
</v-app>
</template>
<script>
import Footer from '@/components/Footer.vue'
export default {
components: {
Footer,
},
async fetch() {
await this.$store.dispatch('store/retrieveSettings')
await this.$store.dispatch('store/retrieveMenus')
},
}
</script>
I don't want to show actHeader
and Footer
components into the first page(/
) but in other pages(/about
) I want to show these components.
I'm already aware of finding out URL and using watch like this:
watch: {
$route (to, from) {
//false actHeader and Footer Components!
}
}
and it's actually working but I'm looking for a better answer, maybe something more logical.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没有特殊的魔术,在每个组件上使用有条件的魔术,也没有更清洁的方法(无需在此处过度工程师)。
There is no special magic, use a conditional on each component, no cleaner way of doing otherwise (no need to over-engineer here).