我有一个带有侧边导航栏的单页应用程序,在列表中有一组锚定标签.
我想根据selectedPage
变量的值显示页面中要显示的内容.以及根据侧栏中单击的链接更改selectedPage
的值.
即使包括在内.防止点击事件,下面的代码不会改变变量的值.我是否应该使用其他条件来代替
我的页面.html
#Navbar for selecting content
<div id="sidebar-wrapper">
<ul class="sidebar-nav">
<li><a href="#" @click.prevent="selectedPage ='Foo'">Foo</a></li>
<li><a href="#" @click.prevent="selectedPage ='Bar'">Bar</a></li>
</ul>
</div>
#Page content
<div id="page-content-wrapper">
<div class="main-content" id="app" v-cloak>
<div class="container-fluid" v-if="selectedPage === 'Foo'">
<h3 class="page-title">{{selectedPage}}</h3>
</div>
<div class="container-fluid" v-if="selectedPage === 'Bar'">
<h3 class="page-title">{{selectedPage}}</h3>
</div>
</div>
</div>
应用程序.js
new Vue({
el: '#app',
data: {
selectedPage: 'Foo',
}
})