gpt4 book ai didi

javascript - 面包屑路由器动态

转载 作者:行者123 更新时间:2023-12-03 21:17:10 25 4
gpt4 key购买 nike

我在尝试制作时遇到问题 breadcrumbvuejs ,当routes没有parameters ,它有效,但对于那些 routes需要一个 parameter ,不知怎么有了parameterbreadcrumb
路线

{
path: '/',
component: () => import('@/components/kit/index'),
name: 'Home',
meta: {
requiresAuth: false,
visibleAfterLogin: true,
breadcrumb: [
{ name: 'Home' }
]
}
},
{
path: '/',
component: () => import('@/pages/kit/Layout'),
children: [
{
path: 'otherouter/:name',
name: 'Other',
components: {
default: () => import('@/components/kit/Other1'),
sidebar: () => import('@/components/kit/Sidebar')
},
meta: {
requiresAuth: false,
visibleAfterLogin: true,
breadcrumb: [
{ name: 'Home', link: 'Home' },
{ name: 'Other' }
]
}
},
{
path: 'studybook/:book',
name: 'Kit',
components: {
default: () => import('@/components/kit/TypeTrails'),
sidebar: () => import('@/components/kit/Sidebar')
},
meta: {
requiresAuth: false,
visibleAfterLogin: true,
breadcrumb: [
{ name: 'Home', link: 'Home' },
{ name: 'Trilhas', link: 'Other' },
{ name: 'Caderno de estudo' }
]
}
}
]
}


面包屑.vue

<template>
<ul class="breadcrumbs">
<li v-for="(item, index) in breadcrumbList" :key="item.name">
<icon name="breadcrumb" size="13px" v-if="index === 0" @click="to(item)" />
<a href="javascript:void(0)" v-if="item.link" @click="to(item)">{{item.name}} </a>
<strong v-else>{{item.name}}</strong>
</li>
</ul>
</template>

<script>
export default {
data(){
return{
breadcrumbList: []
}
},
mounted(){
this.breadcrumbList = this.$route.meta.breadcrumb
},
watch: {
'$route' (){
this.breadcrumbList = this.$route.meta.breadcrumb
}
},
methods: {
to(item){
if(item.link){
this.$router.push({name: item.link})
}
}
}
}
</script>

最佳答案

也许为时已晚,但您可以实现这一点,使面包屑成为接收路由对象的函数,例如:

// router file
{
path: '/items/:id',
...,
meta: {
breadcrumb: (route) => ([
{
name: 'My Items Index view',
to: { name: 'ItemIndex' }
},
{
name: 'My Item Detail view',
to: {
name: 'ItemDetail',
params: { id: route.params.id }
}
}
])
}
}


// app-bar or similar file
export default {
name: 'AppBar',
computed: {
breadcrumb() {
return this.$route.meta.breadcrumb(this.$route)
}
}
}

关于javascript - 面包屑路由器动态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53490949/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com