Hello friends I am tired of getting this error when i count a length of notification by using vue.js and Laravel it show error,Uncaught (in promise) TypeError: Cannot read property 'forEach' of undefined plz help me. here is my code.catch되지 않은 (약속의) 형식 오류 : Laravel에 정의되지 않은 재산 '대해 forEach를'읽기 및
store.js
import Vuex from 'vuex'
import Vue from 'vue'
Vue.use(Vuex)
export const store = new Vuex.Store({
state: {
nots: []
},
getters: {
all_nots(state) {
return state.nots
},
all_nots_count(state) {
return state.nots.length
},
},
mutations: {
add_not(state, not) {
state.nots.push(not)
},
}
})
에게 vue.js 수 없습니다 UnreadNots.vue
<template>
<li>
<a href="/notifications">
Unread notifications
<span class="badge">{{ all_nots_count }}</span>
</a>
</li>
</template>
<script>
export default {
mounted() {
this.get_unread()
},
methods: {
get_unread() {
this.$http.get('/get_unread')
.then((nots) => {
nots.body.forEach((not) => {
this.$store.commit('add_not', not)
})
})
}
},
computed: {
all_nots_count() {
return this.$store.getters.all_nots_count
}
}
}
</script>
web.php
Route::get('get_unread', function(){
return Auth::user()->unreadNotification;
});
그냥'을 console.log (무산자) 같은 REST 스타일의 접근 방식 '과 나던 것이 명백 할 것이다' –
body' 난 빈 데이터를 가지고 –
엡을 너무 그게 너에게 말하는거야? 서버에서 아무 것도 보내지 않았을 것입니다. 브라우저 콘솔의 네트워크 탭을 확인하고 전화가 무엇을 반환하는지 확인하십시오. –