已解决
Vue多级路由展示
来自网友在路上 167867提问 提问时间:2023-11-07 16:20:45阅读次数: 67
最佳答案 问答题库678位专家为你答疑解惑
注意事项:路由出口
<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>
查看全文
99%的人还看了
相似问题
猜你感兴趣
版权申明
本文"Vue多级路由展示":http://eshow365.cn/6-34610-0.html 内容来自互联网,请自行判断内容的正确性。如有侵权请联系我们,立即删除!
- 上一篇: BitBucket 进行代码管理
- 下一篇: Spring Boot Actuator 漏洞利用