根据NUXT中当前路径的切换组件切换

发布于 2025-01-28 14:06:43 字数 1176 浏览 2 评论 0原文

我的布局/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>

我不想显示actheaderfooter 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鸢与 2025-02-04 14:06:43

没有特殊的魔术,在每个组件上使用有条件的魔术,也没有更清洁的方法(无需在此处过度工程师)。

<template>
  <div>
    <act-header v-if="$route.name !== 'index'"></act-header>
    <nuxt />
    <footer-comp v-if="$route.name !== 'index'"></footer-comp>
  </div>
</template>

There is no special magic, use a conditional on each component, no cleaner way of doing otherwise (no need to over-engineer here).

<template>
  <div>
    <act-header v-if="$route.name !== 'index'"></act-header>
    <nuxt />
    <footer-comp v-if="$route.name !== 'index'"></footer-comp>
  </div>
</template>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文