【发布时间】:2020-04-15 03:43:04
【问题描述】:
我正在使用VueJS 创建一个带有多个选项卡的简单应用程序,但似乎无法将选项卡设置为活动状态。它们在组件之间正确切换,但选项卡永远不会激活。我认为文档帮助了 v-model 然后以编程方式添加活动类,但选项卡索引号不会更新,因此切换永远不会更新新选项卡的类。
<template>
<div class="home">
<b-container fluid class="mt-3">
<b-row>
<b-col>
<b-card title="Card Title" body-class="text-center" header-tag="nav">
<template v-slot:header>
<b-nav card-header tabs justified v-model="tabIndex">
<b-nav-item to="/app/page" :active-class="linkClass(0)">Main</b-nav-item>
<b-nav-item to="/app/page/example" :active-class="linkClass(1)">Example</b-nav-item>
<b-nav-item to="/app/page/exampletwo" :active-class="linkClass(2)">Example Two</b-nav-item>
</b-nav>
</template>
<b-card-text>
<!-- With supporting text below as a natural lead-in to additional content. -->
<router-view></router-view>
</b-card-text>
<!-- <b-button variant="primary">Go somewhere</b-button> -->
</b-card>
</b-col>
</b-row>
</b-container>
</div>
</template>
<script>
// @ is an alias to /src
export default {
name: 'AppHome',
data() {
return {
tabIndex: 0
}
},
methods: {
linkClass(idx) {
if (this.tabIndex === idx) {
console.log(idx + ' act')
console.log(this.tabIndex)
return 'active'
} else {
console.log(idx + ' in')
console.log(this.tabIndex)
return ''
}
}
}
}
</script>
我添加的控制台日志是为了检查发生了什么。我无法解决这个问题。
【问题讨论】: