| 123456789101112131415161718192021 |
- import { computed } from 'vue';
- import { useStore } from '@/store';
- import { UserDispatcher, TokenDispatcher } from '@/store/dispatchers';
- export const useUser = () => {
- const store = useStore();
- const userInfo = computed(() => store.state.user);
- const userLoggedIn = computed(() => store.state.user.role !== '游客');
- const userLogOut = () => {
- UserDispatcher.userLogOut();
- TokenDispatcher.destroyToken();
- window.location.href = '/';
- };
- return {
- userInfo,
- userLoggedIn,
- userLogOut,
- };
- };
|