Created
December 31, 2020 11:54
-
-
Save nolimits4web/b0fe318e6d633dfe86121884d215af68 to your computer and use it in GitHub Desktop.
Framework7 v6 Store
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 { createStore } from 'framework7'; | |
// create store | |
const store = createStore({ | |
// start with the state (store data) | |
state: { | |
users: [], | |
// ... | |
}, | |
// actions to operate with state and for async manipulations | |
actions: { | |
getUser({ state }) { | |
// fetch users from API | |
fetch('some-url') | |
.then((res) => res.json()) | |
.then((users) => { | |
// assign new users to store state.users | |
state.users = users; | |
}) | |
}, | |
// ... | |
}, | |
// getters to retreive the state | |
getters: { | |
users({ state }) { | |
return state.users; | |
} | |
} | |
}) | |
// export store | |
export default store; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment