jsfiddle是,https://jsfiddle.net/r6o9h6zm/2/
我在vue js 2中使用了bootstrap nav pill来显示基于所选选项卡的数据(即,如果单击标准的非ac房间,则需要显示该特定房间的记录),但在这里,我在实例中获取所有三个房间,并使用以下内容来实现它,但它没有给出任何结果。
Html:
<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",
},
],
}
})如何才能得到只有选定房间类型的记录,而其他需要隐藏的记录?
发布于 2017-08-26 18:51:04
添加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>这里是updated fiddle的ids
https://stackoverflow.com/questions/45893320
复制相似问题