Version 1.0.0 - Initialisation du depot
This commit is contained in:
30
src/stores/userStore.js
Normal file
30
src/stores/userStore.js
Normal file
@@ -0,0 +1,30 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import { ref, watch } from 'vue';
|
||||
|
||||
export const useUserStore = defineStore('user', () => {
|
||||
const userInfo = ref(null);
|
||||
|
||||
watch(userInfo, (newValue) => {
|
||||
if (newValue) {
|
||||
localStorage.setItem('userInfo', JSON.stringify(newValue));
|
||||
} else {
|
||||
localStorage.removeItem('userInfo');
|
||||
}
|
||||
});
|
||||
|
||||
function setUserInfo(newUserInfo) {
|
||||
console.log("Setting new user info");
|
||||
userInfo.value = newUserInfo;
|
||||
}
|
||||
|
||||
function clearUserInfo() {
|
||||
console.log("Clearing user info");
|
||||
userInfo.value = null;
|
||||
}
|
||||
|
||||
return {
|
||||
userInfo,
|
||||
setUserInfo,
|
||||
clearUserInfo,
|
||||
};
|
||||
})
|
Reference in New Issue
Block a user