Skip to content

Instantly share code, notes, and snippets.

@chriskwan
Created November 30, 2018 23:20
Show Gist options
  • Select an option

  • Save chriskwan/e877255b1077631c7c6a02c617317ee8 to your computer and use it in GitHub Desktop.

Select an option

Save chriskwan/e877255b1077631c7c6a02c617317ee8 to your computer and use it in GitHub Desktop.
Example code in GitHub Gist
import { fetchAccounts } from "../../services/AccountService";
export default {
namespaced: true,
state: {
activeAccountId: null,
accounts: []
},
mutations: {
setAccounts (state, { accounts }) {
state.accounts = accounts;
},
toggleAccountActive (state, { accountId }) {
state.activeAccountId = accountId;
}
},
actions: {
async loadAccounts ({ commit }) {
const accounts = await fetchAccounts();
commit("setAccounts", { accounts });
if (accounts.length) {
commit("toggleAccountActive", { accountId: accounts[0].id });
}
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment