1

I'm using Vue.js app with vue-router in a 3-part component:

App.vue:

<template>
  <div id="app">
    <head>
    </head>
    <NavbarComp/>
    <div>
      <div class="middle">
        <router-view/>
      </div>
    </div>
    <FooterComp/>
  </div>
</template>

The <NavbarComp/> contains a login button, which I'd like to appear only on landing page:

<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>

I tried to define a section in the store, and define the section as a computed property on each component:

  section () {
    this.$store.section = 'login'; 
  }

but could not succeed. So appreciate your hints.

3
  • 1
    Try doing v-if="this.$route.name === 'login-route-name'" Commented Sep 19, 2018 at 12:52
  • 1
    This works. but actually it should be v-if="this.$route.name === 'landing'" . Please asnwer and I'll accept. Thanks! Commented Sep 19, 2018 at 12:55
  • Glad to help :) Commented Sep 19, 2018 at 13:01

1 Answer 1

5

Change the v-if on the button to be:

v-if="this.$route.name === 'whatever-your-route-name-is'" // 'landing' according to your comment
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.