如何仅在某些Vue.js组件上显示navbar元素?

Bab*_*abr 1 vue.js vue-router vue-component

我将Vue.js应用程序与vue-router结合使用,分为3部分:

App.vue:

<template>
  <div id="app">
    <head>
    </head>
    <NavbarComp/>
    <div>
      <div class="middle">
        <router-view/>
      </div>
    </div>
    <FooterComp/>
  </div>
</template>
Run Code Online (Sandbox Code Playgroud)

<NavbarComp/>包含登录按钮,我想只出现在着陆页:

<template>
<div>
<nav>
          <router-link to="/" >
          <h3>My Shining app </h3>
          </router-link> 
          <router-link to="/login">
            <button  v-if="section='landing'"> Login</button>              
          </router-link>
</nav>
</div> 
</template>
Run Code Online (Sandbox Code Playgroud)

我试图section在商店中定义一个,然后将该部分定义为每个组件上的计算属性:

  section () {
    this.$store.section = 'login'; 
  }
Run Code Online (Sandbox Code Playgroud)

但无法成功。因此,感谢您的提示。

Luk*_*den 5

v-if将按钮上的更改为:

v-if="this.$route.name === 'whatever-your-route-name-is'" // 'landing' according to your comment
Run Code Online (Sandbox Code Playgroud)