vue三级路由显示+面包屑

文章借鉴
场景描述:三级路由覆盖二级路由页面,在一级路由页面(主页面显示),并且动态生成面包屑
问题一:如何让三级路由内容显示显示在一级路由页面
可以说是我点级二级路由导航的时候是不发生跳转的,但还要去动态的生成面包屑

利用中间件, 创建一个新vue页面,

<template>
  <router-view></router-view>
</template>

<script>
  export default {
    name: "publish"
  }
</script>

<style scoped>

</style>

router.js引入该页面,作为单独的公共路由页

	path: "/twoPublish",
      meta: {
        title: "政策查询"
      },
      component: () => import('../components/publish.vue'),
      //component: {render(c) {return c('router-view')}}

路由详情

import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: '/circle',
    name: 'Circle',
    component: () => import('../components/CircleMenu')
  },
  {
    path: '/index',
    name: 'Index',
    component: () => import('../views/Index')
  },
  {
    path: '/list',
    name: 'List',
    component: () => import('../components/List')
  },
  {
    path: '/container',
    name: 'Container',
    component: () => import('../views/Container'),
    children: [
      {
        path: '/zccx',
        component: (resolve) => require(['@/views/zccx/index'], resolve),
        name: '政策查询',
        meta: {title: '政策查询', noCache: true, affix: true},
      },
      {
        path: "/twoPublish",
        //component: () => import('@/views/zccx/content/publish'),
        component: {render(c) {return c('router-view')}},
        meta: {title: '政策查询', noCache: true, affix: true},
        children: [
          {
            path: '/zccx/hwhlws',
            component: (resolve) => require(['@/views/zccx/content/hwhlws'], resolve),
            name: '货物和劳务税',
            meta: {title: '货物和劳务税', noCache: true, affix: true},
          },
          {
            path: "/threePublish",
            component: () => import('@/views/zccx/content/publish'),
            meta: {title: '货物和劳务税', noCache: true, affix: true},
            children: [
              {
                path: '/zccx/hwhlws/zzs',
                component: (resolve) => require(['@/views/zccx/content/hwhlws/zzs'], resolve),
                name: '增值税',
                meta: { title: '增值税', noCache: true, affix: true }
              },
            ]
          },
        ]
      },
      {
        path: '/ywcx',
        component: (resolve) => require(['@/views/ywcx/Index'], resolve),
        name: '业务查询',
        meta: { title: '业务查询', noCache: true, affix: true },
      },
    ]
  },
]

const router = new VueRouter({
  mode: 'history',
  base: '/qyzndspbvue/',
  routes
})

export default router

这个我使用的是element的面包屑

<header class="bread">
        <el-breadcrumb separator-class="el-icon-arrow-right">
          <el-breadcrumb-item v-for="(item,index) in breadlist"  :key="index" :to="{ path: '/' }">{{item.meta.title}}</el-breadcrumb-item>
        </el-breadcrumb>
      </header>

// 利用监听器调用 getBreadcrumb方法

watch:{
    $route(e){
      this.getBreadcrumb()
      console.log(e);
    }
  }
    getBreadcrumb(){
      let matched = this.$route.matched;
      this.breadlist=matched
    }
Vue中配置三级路由的方法如下: 首先,在路由配置文件中定义一级路由和二级路由,例如: ```javascript const routes = \[ { path: '/', component: Home, children: \[ { path: 'category', component: Category, children: \[ { path: 'product', component: Product } \] } \] } \] ``` 在上述代码中,`/`是一级路由,`/category`是二级路由,`/category/product`是三级路由。 然后,在一级路由和二级路由的组件中添加 `<router-view></router-view>`,以便渲染三级路由的内容。例如,在Category组件中: ```html <template> <div> <h2>Category</h2> <router-view></router-view> </div> </template> ``` 最后,在Vue实例中使用路由配置: ```javascript const router = new VueRouter({ routes }) new Vue({ router }).$mount('#app') ``` 这样就完成了Vue三级路由配置。当访问`/category/product`时,会先渲染一级路由的组件(Home),然后在其中的`<router-view></router-view>`中渲染二级路由的组件(Category),最后在二级路由的组件中的`<router-view></router-view>`中渲染三级路由的组件(Product)。 引用\[1\]中提到了在配置三级路由时需要注意的问题,即在三级路由的页面中需要添加`<router-view></router-view>`,否则页面会显示空白。这是因为在配置时,二级路由的`component`指向的是面包屑组件路径而非三级页面所在路径,通过`redirect`重定向到三级页面。 引用\[2\]和\[3\]中提到了通过`this.$route.matched.length`来判断一级/二级菜单下是否有三级菜单的方法。根据`this.$route.matched.length`的值,可以判断出点击的一级/二级菜单下是否有三级菜单。 #### 引用[.reference_title] - *1* *2* *3* [vue 动态显示三级路由](https://blog.youkuaiyun.com/Start2019/article/details/119851382)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值