Fix: 修正重定向逻辑 & 使用Pinia管理状态
This commit is contained in:
31
src/stores/navigation.ts
Normal file
31
src/stores/navigation.ts
Normal file
@ -0,0 +1,31 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { computed, ref } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import { navigationConfig } from '@/config/navigation'
|
||||
|
||||
export const useNavigationStore = defineStore('navigation', () => {
|
||||
// Status
|
||||
const route = useRoute()
|
||||
const drawer = ref(false)
|
||||
|
||||
// 当前选中的菜单项
|
||||
const selectedIndex = computed(() => {
|
||||
return navigationConfig.findIndex(item => item.to === route.path)
|
||||
})
|
||||
|
||||
// Actions
|
||||
function toggleDrawer () {
|
||||
drawer.value = !drawer.value
|
||||
}
|
||||
|
||||
function setDrawerOpen (open: boolean) {
|
||||
drawer.value = open
|
||||
}
|
||||
|
||||
return {
|
||||
selectedIndex,
|
||||
drawer,
|
||||
toggleDrawer,
|
||||
setDrawerOpen,
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user