export const useStore = defineStore("main", () => {
const customerId = ref(0)
const customerInfo = ref({})
if (sessionStorage.getItem('store')) {
const storeDate = (JSON.parse(sessionStorage.getItem('store')))
customerId.value=storeDate.customerId
customerInfo.value= {
...storeDate.customerInfo
}
}
window.addEventListener("beforeunload", () => {
sessionStorage.setItem("store", JSON.stringify({
customerId: customerId.value,
customerInfo: {
...customerInfo.value
}
}));
});
return {
customerInfo,
customerId,
}
})
Vue3 attribute pinia (store) data loss - record it
Guess you like
Origin blog.csdn.net/qq_48109675/article/details/130445428
Recommended
Ranking