const personalDetailsData = ref([]);
onMounted(async () => {
const localPersonalDetailsData = JSON.parse(localStorage.getItem('personalDetailsEducationPanels')) || [];
if (localPersonalDetailsData.length) {
personalDetailsPanelArr.value = localPersonalDetailsData;
}
});
watch(personalDetailsPanelArr, (newValue) => {
personalDetailsData.value = newValue;
localStorage.setItem('personalDetailsEducationPanels', JSON.stringify(newValue));
}, {
deep: true
});
export const useLoginStore = defineStore('login', () => {
const productCommentsStore = useProductCommentsStore();
const updateLoginId = (newLoginId) => {
productCommentsStore.setLoginId(newLoginId);// передача id другому стору
};
const handleSubmit = async () => {
const loginData = {
login: login.value,
password: password.value,
}
try {
const resp = await loginUser(loginData);
const token = resp.token;
const login = resp.login;
const id = resp._id;
localStorage.setItem('loginId', id);
updateLoginId(id);
respAuthMessage.value = resp;
updateAuthentication(token, login);
if(isAuthenticated.value) {
router.push('/');
}
} catch (error) {
console.error('Error:', error);
}
}
return {
...
}
})
//-------//
export const useProductCommentsStore = defineStore('productComments', () => {
const loginId = ref(localStorage.getItem('loginId') || null);
const setLoginId = (newLoginId) => {
loginId.value = newLoginId; //присваивание актуального id
};
return {
setLoginId
}
})