在bootstrap官方文档中,我看到了很酷的导航丸。 就是这样。
<div class="nav flex-column nav-pills" id="v-pills-tab" role="tablist" aria-orientation="vertical">
<a class="nav-link active" id="v-pills-home-tab" data-toggle="pill" href="#v-pills-home" role="tab" aria-controls="v-pills-home" aria-selected="true">Home</a>
<a class="nav-link" id="v-pills-profile-tab" data-toggle="pill" href="#v-pills-profile" role="tab" aria-controls="v-pills-profile" aria-selected="false">Profile</a>
<a class="nav-link" id="v-pills-messages-tab" data-toggle="pill" href="#v-pills-messages" role="tab" aria-controls="v-pills-messages" aria-selected="false">Messages</a>
<a class="nav-link" id="v-pills-settings-tab" data-toggle="pill" href="#v-pills-settings" role="tab" aria-controls="v-pills-settings" aria-selected="false">Settings</a>
</div>
<div class="tab-content" id="v-pills-tabContent">
<div class="tab-pane fade show active" id="v-pills-home" role="tabpanel" aria-labelledby="v-pills-home-tab">...</div>
<div class="tab-pane fade" id="v-pills-profile" role="tabpanel" aria-labelledby="v-pills-profile-tab">...</div>
<div class="tab-pane fade" id="v-pills-messages" role="tabpanel" aria-labelledby="v-pills-messages-tab">...</div>
<div class="tab-pane fade" id="v-pills-settings" role="tabpanel" aria-labelledby="v-pills-settings-tab">...</div>
</div>
这是我目前用于导航的代码。
<ul class="nav flex-column">
<li class="nav-item">
<router-link to="/studentDashboard">Dashboard</router-link>
</li>
<li class="nav-item">
<router-link to="/buyPapers">Buy papers</router-link>
</li>
<li class="nav-item" >
<router-link to="/myPapers">My papers</router-link>
</li>
</ul>
在此代码中,我应该更改哪些药片?
答案 0 :(得分:7)
<router-link> by defult is rendered as an achor tag `<a>`.
Bootstap 4 nav-pills具有<a>
标记,其中包含类nav-link
。如下:
<ul class="nav nav-pills">
<li class="nav-item">
<a class="nav-link active" href="#">Active</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
</li>
</ul>
只需将该课程添加到<router-link>
<li class="nav-item">
<router-link class="nav-link" active-class="active" to="/studentDashboard">Dashboard</router-link>
</li>
要将active
类添加到代表当前活动路线的nav-pill中,请在每个`
active-class
道具
答案 1 :(得分:1)
使用活动标签和标签内容的Vue路由器控件显示而不是Bootstrap。每个tab-pane
都应该有active
类,因为路由器用于控制路由器视图的显示......
const home = { template: '<div class="tab-pane active">Home...</div>' }
const profile = { template:'<div class="tab-pane active">Profile.. </div>' }
const more = { template:'<div class="tab-pane active">More..</div>' }
然后,使用一种方法在每个导航丸上有条件地设置active
类......
methods: {
activeClass: function (...names) {
for (let name of names) {
if (name == this.$route.name)
return 'active';
}
}
}
HTML
<ul class="nav nav-pills">
<li class="nav-item">
<router-link to="/home" class="nav-link" :class="activeClass('home')">Home</router-link>
</li>
<li class="nav-item">
<router-link to="/profile" class="nav-link" :class="activeClass('profile')">Profile</router-link>
</li>
<li class="nav-item">
<router-link to="/more" class="nav-link" :class="activeClass('more')">More</router-link>
</li>
</ul>
<div class="tab-content">
<router-view></router-view>
</div>
答案 2 :(得分:0)
这对我有用。
<b-nav-item to="/home" href="#">Home</b-nav-item>
<b-nav-item to="/faq" href="#">FAQ</b-nav-item>
<b-nav-item to="/contact" href="#">Contact</b-nav-item>