Answer the question
In order to leave comments, you need to log in
How to print a Promise object using v-for directive?
Cannot print Promise object. How to fix?
<div v-for="newsItem in newsList" >{{newsItem.title}}</div>
const store = new Vuex.Store({
state: {
news: null
},
getters: {
NEWS: state => {
return state.news;
},
},
mutations: {
SET_NEWS: (state, payload) => {
state.news = payload;
},
},
actions: {
GET_NEWS: async (context, payload) => {
let data = axios.get('http://news/news_list').then(response => {return response.data});
context.commit('SET_NEWS', data);
}
}
});
const app = new Vue({
el: '#content',
store,
computed: {
newsList() {
return this.$store.getters.NEWS;
},
},
mounted() {
this.$store.dispatch('GET_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