初始化仓库
This commit is contained in:
22
src/store/user.ts
Normal file
22
src/store/user.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import Cookies from 'js-cookie';
|
||||
|
||||
const USERNAME_KEY = 'username';
|
||||
|
||||
export const useUserStore = defineStore('user', {
|
||||
state: () => ({
|
||||
username: Cookies.get(USERNAME_KEY) || null,
|
||||
}),
|
||||
actions: {
|
||||
async fetchUserInfo() {
|
||||
// Simulate API call
|
||||
const fetchedUsername = 'mock_user';
|
||||
this.username = fetchedUsername;
|
||||
Cookies.set(USERNAME_KEY, fetchedUsername);
|
||||
},
|
||||
clearUserInfo() {
|
||||
this.username = null;
|
||||
Cookies.remove(USERNAME_KEY);
|
||||
},
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user