前端和json优化
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<div class="change-home" v-if="isAdmin">
|
||||
<div class="change-home">
|
||||
<div class="change-home-item" @click="changeHome">
|
||||
<span v-if="home">前往用户页</span>
|
||||
<span v-else>前往管理页</span>
|
||||
@@ -10,14 +10,8 @@
|
||||
import { ref, onMounted } from 'vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
|
||||
const isAdmin = ref<boolean>(false);
|
||||
const home = ref<boolean>(false);
|
||||
const router = useRouter();
|
||||
const routes = router.getRoutes();
|
||||
|
||||
function hasAdmin(){
|
||||
return routes.some((route: any) => route.path.startsWith('/admin'));
|
||||
}
|
||||
|
||||
function changeHome(){
|
||||
if(home.value){
|
||||
@@ -27,10 +21,7 @@ function changeHome(){
|
||||
}
|
||||
home.value = !home.value;
|
||||
}
|
||||
onMounted(() => {
|
||||
isAdmin.value = hasAdmin();
|
||||
home.value = router.currentRoute.value.path.startsWith('/admin');
|
||||
});
|
||||
|
||||
</script>
|
||||
<style scoped lang="scss">
|
||||
</style>
|
||||
Reference in New Issue
Block a user