Skip to content

Instantly share code, notes, and snippets.

@nolimits4web
Created December 31, 2020 11:54
Show Gist options
  • Save nolimits4web/b0fe318e6d633dfe86121884d215af68 to your computer and use it in GitHub Desktop.
Save nolimits4web/b0fe318e6d633dfe86121884d215af68 to your computer and use it in GitHub Desktop.
Framework7 v6 Store
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