ace*_*ace 9 vue.js vuejs2 bootstrap-vue
我正在使用Bootstrap-vue tabs。这是标签的 HTML:
<b-tabs>
<b-tab title="Exotic Dogs" href="#dogs">
<br>Dogs here
</b-tab>
<b-tab title="Exotic Cats" href="#cats">
<br>Cats here
</b-tab>
</b-tabs>
Run Code Online (Sandbox Code Playgroud)
这是猫的路线:
{
path: '/animals/:id#cats',
name: 'getCats',
component: Animals // removed from HTML to simplify
},
Run Code Online (Sandbox Code Playgroud)
在组件代码中:
this.$router.replace({ name: 'getCats', params: { id: this.$route.params.id }})
Run Code Online (Sandbox Code Playgroud)
这将需要:
本地主机:3000/animals/234909888#cats
但是狗选项卡是打开的(第一个选项卡)而不是猫选项卡。刷新浏览器也会显示空白页面。
如何解决这个问题?
您可以尝试添加v-model="tabIndex"
到<b-tabs>
标签,并用于$route.hash
将其设置在mounted()
.
<b-tabs v-model="tabIndex">
<b-tab title="Exotic Dogs" href="#dogs">
<br>Dogs here
</b-tab>
<b-tab title="Exotic Cats" href="#cats">
<br>Cats here
</b-tab>
</b-tabs>
Run Code Online (Sandbox Code Playgroud)
export default {
...
data() {
return {
tabIndex: 0,
tabs: ['#dogs', '#cats']
}
},
mounted() {
this.tabIndex = this.tabs.findIndex(tab => tab === this.$route.hash)
}
...
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
8076 次 |
最近记录: |