I have a JSON
file containing some data that needs to be fetched and displayed in a component.
In the actions of my Vuex
store, I've implemented:
async getTodos (context) {
const todos = []
const response = await fetch('../../data/todos.json')
const responseData = await response.json()
todos.push(responseData)
context.commit('getTodos', todos)
}
Mutations:
getTodos (state, payload) {
state.todos = payload
}
And the state looks like this:
state () {
return {
todos: []
}
}
Now, how can I access these todos
from the state and display them when the Homepage is mounted?
An example of the JSON file content:
[
{
"id": "1",
"title": "1st todo",
"description": "First task",
"dueTo": "2021-10-03"
},
{
"id": "2",
"title": "2nd todo",
"description": "Second task",
"dueTo": "2021-10-02"
}
]