Answer the question
In order to leave comments, you need to log in
Show first element computed Vue.js?
Why is there an error in the console
when trying to show the first element of a list from computed
main.js:87126 [Vue warn]: Error in render: "TypeError: Cannot read property '0' of null"
Although everything is displayed on the page .
<div class="col-sm-9">
<div class="jumbotron">
{{itemsList[0]}}
<hr class="my-4">
</div>
</div>
computed: {
itemsList() {
return this.$store.getters.MY_ITEMS;
},
}
export const SET_MY_ITEMS = 'SET_MY_ITEMS';
export const myStore = {
state: {
my_items: null,
},
getters: {
MY_ITEMS: state => {
return state.my_items;
},
},
mutations: { // commit
[SET_MY_ITEMS](state, my_items) {
state.my_items = my_items;
},
},
actions: { // dispatch
[SET_MY_ITEMS](context) {
axios.post('/api/index').then((response) => {
context.commit('SET_MY_ITEMS', response['data']['list']);
}).catch(error => {
});
},
},
};
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