Powiadomienia
Wyczyść wszystko
BugOverflow
1
Wpisy
1
Użytkownicy
0
Reactions
982
Widoki
0
15/05/2022 3:22 pm
Rozpoczynający temat
example
1 odpowiedź
0
15/05/2022 3:24 pm
Rozpoczynający temat
let store = new Vuex.Store({
state: {
user: null,
},
mutations: {
setUser: function (state, user) {
state.user = user;
},
<p v-if="!this.$store.state.user">Waiting...</p>
async function checkUserSession() {
return axios.get("/api/user").then(async (response) => {
store.commit('setUser', response.data.data);
}).catch(async (error) => {
store.commit('setUser', null);
});
}
router.beforeEach(async (to, from, next) => {
if (!store.state.user) {
await checkUserSession();
}
