Created
November 30, 2018 23:20
-
-
Save chriskwan/e877255b1077631c7c6a02c617317ee8 to your computer and use it in GitHub Desktop.
Example code in GitHub Gist
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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