状态管理

This commit is contained in:
2025-11-11 20:34:58 +08:00
parent c20dd5955a
commit c752bfd3c2
11 changed files with 179 additions and 80 deletions
+26
View File
@@ -0,0 +1,26 @@
// stores/user.js
import { defineStore } from "pinia";
import { ref, computed } from "vue";
// 组合式 API 写法 (推荐)
export const useUserStore = defineStore("user", () => {
// 状态 (State)
const userInfo = ref(null);
const token = ref("");
const isLoggedIn = ref(false);
const logout = () => {
isLoggedIn.value = false;
};
const login = () => {
isLoggedIn.value = true;
};
return {
userInfo,
token,
isLoggedIn,
logout,
login,
};
});