在我的 vue 应用程序中,我有一个包含一些选项卡的页面。我想根据不同的路线更改/显示选项卡。
为此,我用这个答案作为参考。
总的来说,这工作正常!我甚至可以通过在移动设备上滑动来更改选项卡(这要归功于.@changev-tabs-items
但是:单击选项卡标签时,由 加载的组件将安装两次。滑动时,它只安装一次。<router-view>
原因必须与s循环内的存在有关。<router-view><v-tab-item>
如果我把它放在这个环路之外,子组件就会正确安装一次。不幸的是,我不能再使用滑动来更改选项卡,因为内容是分离的。
所以:是否有机会同时具有这两种功能(动态路由内容和可移动性)?
谢谢你们!
维尤:
<template>
<!-- [...] -->
<v-tabs centered="centered" grow v-model="activeTab">
<v-tab v-for="tab of tabs" :key="tab.id" :id="tab.id" :to="tab.route" exact>
<v-icon>{{ tab.icon }}</v-icon>
</v-tab>
<v-tabs-items v-model="activeTab" @change="updateRouter($event)">
<v-tab-item v-for="tab of tabs" :key="tab.id" :value="resolvePath(tab.route)" class="tab_content">
<!-- prevent loading multiple route-view instances -->
<router-view v-if="tab.route === activeTab" />
</v-tab-item>
</v-tabs-items>
</v-tabs>
<!-- [...] -->
</template>
<script>
data: () => ({
activeTab: '',
tabs: [
{id: 'profile', icon: 'mdi-account', route: '/social/profile'},
{id: 'friends', icon: 'mdi-account-group', route: '/social/friends'},
{id: 'settings', icon: 'mdi-cogs', route: '/social/settings'},
]
}),
methods: {
updateRouter(tab:string) {
this.$router.push(tab)
}
},
</script>
路由器:
{
path: "/social",
component: () => import("../views/Social.vue"),
meta: {
requiresAuth: true
},
children: [
{
path: "profile",
component: () => import("@/components/social/Profile.vue")
},
{
path: "friends",
component: () => import("@/components/social/Friendlist.vue")
},
{
path: "settings",
component: () => import("@/components/social/ProfileSettings.vue")
}
]
}
一只甜甜圈
元芳怎么了
相关分类