Answer the question
In order to leave comments, you need to log in
How to display all records from a db table using Vuex?
Friends, I just started studying Vuex and I need to analyze the following example:
using Vuex, display all records from the database table in the simplest version without any components and place all the code in one file. Here's what I tried to do, but it doesn't work:
const store = new Vuex.Store({
state: {
news: null
},
mutations: {
async getNews (state) {
try {
axios
.get('http://news/news_list')
.then(response => (state.news = response.data));
} catch (error) {
console.error('Нет новостей', error)
}
}
}
})
store.commit('getNews')
console.log(store.state.news)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question