Created
August 8, 2021 06:06
-
-
Save DJanoskova/4ae7ee1660ad59c0cbac65f4aed3ae75 to your computer and use it in GitHub Desktop.
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
| const store = { | |
| state: { | |
| posts: [] | |
| }, | |
| mutations: { | |
| POSTS_SET(state, data) { | |
| state.posts = data | |
| } | |
| }, | |
| actions: { | |
| async POSTS_FETCH(context) { | |
| const response = await fetch('https://jsonplaceholder.typicode.com/posts') | |
| const data = await response.json() | |
| context.mutations.POSTS_SET(data) | |
| } | |
| }, | |
| getters: { | |
| posts (state) { | |
| return state.posts | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment