Updated useState composable
This commit is contained in:
parent
286605695b
commit
581efb8ddb
|
@ -46,7 +46,7 @@ import { useSession } from '@/core/composables/useSession';
|
|||
import UserPanel from '@/components/UserPanel.vue';
|
||||
|
||||
const session = useSession();
|
||||
const { getUser } = useState();
|
||||
const user = getUser;
|
||||
const state = useState();
|
||||
const user = state.getUser();
|
||||
const token = session.getToken();
|
||||
</script>
|
||||
|
|
|
@ -62,7 +62,7 @@ const darkMode = computed({
|
|||
},
|
||||
});
|
||||
|
||||
const user = state.getUser;
|
||||
const user = state.getUser();
|
||||
const token = session.getToken();
|
||||
|
||||
onMounted(() => {
|
||||
|
|
|
@ -6,15 +6,32 @@ interface User {
|
|||
nickname: string;
|
||||
}
|
||||
|
||||
interface useState {
|
||||
getUser: () => ComputedRef<User>;
|
||||
setUser: (data: User) => void;
|
||||
getRoles: () => ComputedRef<string[]>;
|
||||
setRoles: (data: string[]) => void;
|
||||
}
|
||||
|
||||
const user: Ref<User> = ref({
|
||||
id: 0,
|
||||
username: '',
|
||||
nickname: '',
|
||||
});
|
||||
|
||||
const roles = ref([]);
|
||||
const roles: Ref<string[]> = ref([]);
|
||||
|
||||
export function useState(): useState {
|
||||
function getUser(): ComputedRef<User> {
|
||||
return computed(() => {
|
||||
return {
|
||||
id: user.value.id,
|
||||
username: user.value.username,
|
||||
nickname: user.value.nickname,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
export function useState() {
|
||||
function setUser(data: User): void {
|
||||
user.value = {
|
||||
id: data.id,
|
||||
|
@ -23,21 +40,20 @@ export function useState() {
|
|||
};
|
||||
}
|
||||
|
||||
const getUser: ComputedRef<User> = computed(() => {
|
||||
return {
|
||||
id: user.value.id,
|
||||
username: user.value.username,
|
||||
nickname: user.value.nickname,
|
||||
};
|
||||
});
|
||||
function getRoles(): ComputedRef<string[]> {
|
||||
return computed(() => {
|
||||
return roles.value;
|
||||
});
|
||||
}
|
||||
|
||||
/* function setRoles(data) {
|
||||
function setRoles(data: string[]): void {
|
||||
roles.value = data;
|
||||
} */
|
||||
}
|
||||
|
||||
return {
|
||||
roles,
|
||||
getUser,
|
||||
setUser,
|
||||
getRoles,
|
||||
setRoles,
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue