我在一个由3部分组成的组件中使用Vue.js应用程序和vue-路由器:
App.vue:
<template>
<div id="app">
<head>
</head>
<NavbarComp/>
<div>
<div class="middle">
<router-view/>
</div>
</div>
<FooterComp/>
</div>
</template><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>我试图在存储区中定义一个section,并将该节定义为每个组件上的计算属性:
section () {
this.$store.section = 'login';
}但没能成功。所以感谢你的暗示。
发布于 2018-09-19 12:56:48
将按钮上的v-if更改为:
v-if="this.$route.name === 'whatever-your-route-name-is'" // 'landing' according to your commenthttps://stackoverflow.com/questions/52406230
复制相似问题