Reputation: 2081
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.
Upvotes: 1
Views: 1641
Reputation: 734
Change the v-if
on the button to be:
v-if="this.$route.name === 'whatever-your-route-name-is'" // 'landing' according to your comment
Upvotes: 5