Vue多级路由展示

注意事项:路由出口

 <router-view :key="key" />

注意事项:路径层级


// --------- 文件层级展示 ----------//
// 文件: src
//   文件: layouts
//     文件:AppMain > index.vue   // 二级展示出口
//   文件: views
//     文件:personnel > index.vue // 三级展示出口
//       文件:health > index.vue  // 展示内容
// 文本:App.vue                   // 总出口

// ---------- 路由报文展示 ----------//
// 二级展示
data: [
   "path": '/',
   "component": 'layouts',
   "redirect": 'noRedirect',
   "meta": { "title": '系统层级' },
   "children": [
      {
       "path": '/',
       "component": 'layouts',
       "meta": { "title": '第一层' },
       "children": [
        {
          "path": 'health',
          "component": 'views/personnel/health/index',
          "meta": { "title": '第二层' }, 
          "name": 'health',
          "sort": '1',
        }
        ],
        "name": 'layouts',
        "sort": '1',
      }
    ],
 ]
// 三级展示
data: [
   "path": '/',
   "component": 'layouts',
   "redirect": 'noRedirect',
   "meta": { "title": '系统层级' },
   "children": [
      {
       "path": '/',
       "component": 'layouts',
       "meta": { "title": '第一层' },
       "children": [
        {
          "path": 'personnel',
          "component": 'views/personnel/index',
          "meta": { "title": '第二层' }, 
          "children": [
            {
              "path": 'health',
              "component": 'views/personnel/health/index',
              "meta": { "title": '第三层' }, 
              "name": 'health',
              "sort": '1',
            }
           ],
           "name": 'personnel',
           "sort": '1',
          }
        ],
        "name": 'layouts',
        "sort": '1',
      }
    ],
 ]

// ---------- 文件内容展示 ----------//
// APP.vue   // 总出口
  <template>
    <div id="App>
      <router-view />
    </div>
  </template>
  <script>
    export default {
     name: 'App',
     data() {
       return {}
      }
    }
  </script>

// src > layouts > AppMain > index.vue   //  二级出口
  <template>
    <div class="AppMain">
     <transition mode="out-in">  
       <keep-alive :include="includeRoutes" :max="20">
         <router-view :key="key" />
       </keep-alive>    
     </transition>
    </div>
  </template>
  <script>
    import { mapActions, mapGetters } from 'vueX'
    export default {
     name: 'AppMain',
     data() {
       return {}
      },
     computed: {
      ...mapGetters({
          visitedRoutes: 'tabsBar/visitedRoutes',   // store > modules > tabsBar
       }),
       includeRoutes() {
        let newArr = []
        newArr = this.visitedRoutes.map(item => !item.meta.noKeepAlive && item.name)
        return newArr
       },
       key() {
         return this.$route.path
       }
     },
     watch: {
     },
     created() {
     },
     mounted() {
     },
     methods: {
      ...mapActions({
        foldSideBar: 'settings/foldSideBar',    // store > modules > settings
       })
     }
    }
  </script>

// src > views > personnel > index.vue  // 三级出口
   <template>
    <div class="personnel">
     <transition mode="out-in">  
       <keep-alive>
         <router-view :key="key" />
       </keep-alive>    
     </transition>
    </div>
  </template>
  <script>
    export default {
     name: 'personnel',
     data() {
       return {}
      },
     computed: {
      key() {
        return this.$route.path
      }
    }
  </script>

// src > views > personnel > health > index.vue   // 内容展示
   <template>
    <div class="health">
      <p>{{ content }}</p>
    </div>
  </template>
  <script>
    export default {
     name: 'health',
     data() {
       return {
         content: '展示的内容',
       }
      },
    }
  </script>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值