Bootstrap nav-pills in vue js 2



jsfiddle 是,https://jsfiddle.net/r6o9h6zm/2/

我在 vue js 2 中使用了引导导航药丸,根据所选选项卡显示数据(即,如果单击标准非空调房间,则需要显示该特定房间的记录(,但在这里我得到了实例中的所有三个房间,我使用了以下内容来实现它, 但它没有给出任何结果。

目录:

<div id="app">
<div class="room-tab">
<ul class="nav nav-pills nav-justified tab-line">
<li v-for="(item, index) in items" v-bind:class="{'active' : index === 0}">
<a :href="item.id" data-toggle="pill"> {{ item.title }} </a>
</li>
</ul>
<div class="room-wrapper tab-content">
<div  v-for="(item, index) in items" v-bind:class="{'active' : index === 0}" :id="item.id">
<div class="row">
<div class="col-md-8">
<div class="col-md-4">
<h3>{{item.title}}</h3>
<p>{{item.content}}</p>
</div>
</div>
</div><br>
</div>
</div>

脚本:

new Vue({
el: '#app',
data: {
items: [
{
id: "0",
title: "Standard Non AC Room",
content: "Non AC Room",
},
{
id: "1",
title: "Standard AC Room",
content: "AC Room",
},
{
id: "2",
title: "Deluxe Room",
content: "Super Speciality Room",
},
],
}
})

如何获得仅包含所选房型记录的结果,而其他房型需要隐藏?

添加data属性currentSelected: 0以跟踪选择了哪个房间

new Vue({
el: '#app',
data: {
currentSelected: 0,
items: [
{
id: "0",
title: "Standard Non AC Room",
content: "Non AC Room",
},
{
id: "1",
title: "Standard AC Room",
content: "AC Room",
},
{
id: "2",
title: "Deluxe Room",
content: "Super Speciality Room",
},
],
},
methods:{
selectRoom(index){
this.currentSelected = index
}
}
}) 

在每个导航药丸上添加一个点击侦听器以更改所选房间

<div id="app">
<div class="room-tab">
<ul class="nav nav-pills nav-justified tab-line">
<li 
v-for="(item, index) in items" 
v-bind:class="{'active' : index === currentSelected}"
@click="selectRoom(index)">
<a> {{ item.title }} </a>
</li>
</ul>
<div class="room-wrapper tab-content">
<div  
v-for="(item, index) in items" 
v-bind:class="{'active' : index === 0}"
v-if="index === currentSelected"
:key="item.id">
<div class="row">
<div class="col-md-8">
<div class="col-md-4">
<h3>{{item.title}}</h3>
<p>{{item.content}}</p>
</div>
</div>
</div><br>
</div>
</div>

这里是更新的小提琴

最新更新