修正使用重定向时左侧菜单不会跟踪的问题

This commit is contained in:
洛洛希雅Lolosia 2023-03-03 11:30:15 +08:00
parent 42ed4f08b5
commit d27db128ea

View File

@ -11,7 +11,7 @@
:collapse-transition="false" :collapse-transition="false"
mode="vertical" mode="vertical"
> >
<sidebar-item v-for="route in allRoutes" :key="route.path" :item="route" :base-path="route.path" /> <sidebar-item v-for="r in allRoutes" :key="r.path" :item="r" :base-path="r.path" />
</el-menu> </el-menu>
</el-scrollbar> </el-scrollbar>
</div> </div>
@ -20,18 +20,16 @@
<script setup lang="ts"> <script setup lang="ts">
import { computed } from 'vue' import { computed } from 'vue'
import { storeToRefs } from 'pinia/dist/pinia' import { storeToRefs } from 'pinia/dist/pinia'
import { useRoute } from 'vue-router' import { useRoute } from "vue-router";
import Logo from './Logo.vue' import Logo from './Logo.vue'
import SidebarItem from './SidebarItem.vue' import SidebarItem from './SidebarItem.vue'
import { useBasicStore } from '@/store/basic' import { useBasicStore } from '@/store/basic'
const { settings, allRoutes, sidebar } = storeToRefs(useBasicStore()) const { settings, allRoutes, sidebar } = storeToRefs(useBasicStore())
const { meta, path } = useRoute() const route = useRoute()
const activeMenu = computed(() => { const activeMenu = ref<any>(route.path);
// if set path, the sidebar will highlight the path you set
if (meta.activeMenu) { watch(() => route.path, val => {
return meta.activeMenu activeMenu.value = val
}
return path
}) })
</script> </script>
<style lang="scss"> <style lang="scss">