[Vuejs]-Vuex function execute before the other

0👍

I will just show you my logout function, perhpas it will help you:

  logout() {
      this.$store.dispatch("setToken", null);
      this.$store.dispatch("setAdmin", null);
      this.$router.push({
        name: "root"
      });
    }

and in the store:

mutations: {
    setToken (state, token) {
      state.token = token
      if (token) {
        state.isAdminLoggedIn = true
      } else {
        state.isAdminLoggedIn = false
      }
    },
    setAdmin (state, admin) {
      state.admin = admin
    }
  },
  actions: {
    setToken ({ commit }, token) {
      commit('setToken', token)
    },
    setAdmin ({ commit }, admin) {
      commit('setAdmin', admin)
    }

Leave a comment