Notifications
Clear all
BugOverflow
1
Posty
1
Users
0
Reactions
728
Widok
0
15/05/2022 3:22 pm
Topic starter
example
1 Answer
0
15/05/2022 3:24 pm
Topic starter
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(); }