| 1 | import { useLoadingBar } from "naive-ui" |
| 2 | import { onMounted } from "vue" |
| 3 | import { useRouter } from "vue-router" |
| 4 | import { useMainStore } from "@/stores/main" |
| 5 | |
| 6 | export function useLoadingBarSetup() { |
| 7 | const router = useRouter() |
| 8 | const mainStore = useMainStore() |
| 9 | |
| 10 | onMounted(() => { |
| 11 | const loadingBar = useLoadingBar() |
| 12 | router.beforeEach((to, current) => { |
| 13 | if (to.path !== current.path) { |
| 14 | loadingBar?.start() |
| 15 | } |
| 16 | }) |
| 17 | router.afterEach(() => loadingBar?.finish()) |
| 18 | mainStore.setLoadingBar(loadingBar) |
| 19 | }) |
| 20 | } |