Browse Source

masger

master
邓宏 3 years ago
parent
commit
a92069633c
  1. 15
      src/layout/components/appMain.vue
  2. 4
      src/layout/components/sidebar/sidebarItem.vue
  3. 22
      src/router/index.js
  4. 3
      src/store/modules/data.js
  5. 16
      src/views/Demo.vue
  6. 2
      src/views/Home.vue

15
src/layout/components/appMain.vue

@ -2,22 +2,25 @@
</style> </style>
<template> <template>
<!-- <transition name="fade-transform" mode="out-in"> -->
<router-view v-slot="{ Component }">
<transition name="fade-transform" mode="out-in"> <transition name="fade-transform" mode="out-in">
<router-view v-slot="{ Component }" :key="$route.path"> <keep-alive :include="cachedViews">
<keep-alive :include="cacheViews"> <component :is="Component" v-if="cached" :key="$route.path"/>
<component :is="Component"/>
</keep-alive> </keep-alive>
</router-view>
</transition> </transition>
<component :is="Component" :key="$route.path" v-if="!cached"/>
</router-view>
</template> </template>
<script> <script>
import { defineComponent } from 'vue' import { defineComponent, shallowRef } from 'vue'
export default defineComponent({ export default defineComponent({
name:"appMain", name:"appMain",
setup() { setup() {
var _data={ var _data={
cacheViews:['home','about'] cachedViews:shallowRef(['about','home','demo']),
cached:true,
} }
return _data; return _data;

4
src/layout/components/sidebar/sidebarItem.vue

@ -2,7 +2,7 @@
</style> </style>
<template> <template>
<template v-if="!item?.hidden"> <template v-if="!item?.meta?.hidden">
<template v-if="hasOneShowingChild(item.children, item) && (!onlyOneChild.children||onlyOneChild.noShowingChildren) && !item.alwaysShow"> <template v-if="hasOneShowingChild(item.children, item) && (!onlyOneChild.children||onlyOneChild.noShowingChildren) && !item.alwaysShow">
<el-menu-item :index=" /^\//.test(onlyOneChild.path)?onlyOneChild.path:basePath " > <el-menu-item :index=" /^\//.test(onlyOneChild.path)?onlyOneChild.path:basePath " >
<item :icon="onlyOneChild.meta?.icon||''" :title="onlyOneChild.meta?.title||''"/> <item :icon="onlyOneChild.meta?.icon||''" :title="onlyOneChild.meta?.title||''"/>
@ -45,7 +45,7 @@ export default defineComponent({
onlyOneChild:shallowRef({}), onlyOneChild:shallowRef({}),
hasOneShowingChild(children=[],parent){ hasOneShowingChild(children=[],parent){
var showingChildren=children.filter(i=>{ var showingChildren=children.filter(i=>{
if(i.hidden)return false; if(i?.meta?.hidden)return false;
else{ else{
_data.onlyOneChild.value=i; _data.onlyOneChild.value=i;
return true return true

22
src/router/index.js

@ -14,22 +14,12 @@ export const menu=[
icon:"atm", icon:"atm",
}, },
children:[ children:[
{ {path:"path1", meta:{ title:"about", icon:"atm", }, component:()=>import("@/views/About.vue")},
path:"path1", {path:"path2", meta:{ title:"home", icon:"atm", }, component:()=>import("@/views/Home.vue")},
component:()=>import("@/views/About.vue"), {path:"path3", meta:{ title:"demo", hidden:true, icon:"atm", }, component:()=>import("@/views/Demo.vue")},
meta:{
title:"about", {path:"path4", meta:{ title:"demo2", icon:"atm", }, component:()=>import("@/views/Demo.vue")},
icon:"atm", {path:"path5", meta:{ title:"demo3", icon:"atm", }, component:()=>import("@/views/Demo.vue")},
},
},
{
path:"/path2",
component:()=>import("@/views/Home.vue"),
meta:{
title:"home",
icon:"atm",
}
},
], ],
} }
] ]

3
src/store/modules/data.js

@ -3,6 +3,9 @@ export default {
state:{ state:{
menu:{}, menu:{},
}, },
getters:{
menuName:state=>Object.values(state.menu).map(v=>v.name)
},
mutations:{ mutations:{
setMenu(state,val){ setMenu(state,val){
state.menu[val.key]=val.item state.menu[val.key]=val.item

16
src/views/Demo.vue

@ -0,0 +1,16 @@
<template>
<div>
<h1>demo</h1>
<button @click="$router.back()">上一页</button>
</div>
</template>
<script>
import { defineComponent } from 'vue'
export default defineComponent({
name:"demo",
setup() {
console.log("--------------demo-------------")
},
})
</script>

2
src/views/Home.vue

@ -1,7 +1,7 @@
<template> <template>
<div class="home"> <div class="home">
<h1>This is an home page</h1> <h1>This is an home page</h1>
<svg-icon iconClass="atm"/> <svg-icon iconClass="atm" @click="$router.push({path:'/path3'})"/>
</div> </div>
</template> </template>

Loading…
Cancel
Save