The data retrieve using axios is not displaying on vue eventhough in vue-dev tools there is data in it. Plus i'm getting errors : [Vue warn]: Error in render: "TypeError: Cannot read property 'logbook_id' of null" and TypeError: Cannot read property 'logbook_id' of null. New in Laravel. Thanks.
Vue Component
<template>
<div class="container">
<h1 v-for="log in logbook" v-bind:key="log.logbook_id" > {{ log.title }}
</h1>
</div>
</template>
<script>
export default {
data(){
return{
logbook:{},
}
},
methods:{
fetchLog(){
const url = `/api/logbook/${this.$route.params.id}`;
axios.get(url).then(response => this.logbook = response.data);
},
},
mounted() {
console.log('Component mounted.');
this.fetchLog();
}
}
Controller
public function show($id)
{
$log = logbook::where(['logbook_id' => $id])
->first();
return response($log);
}
json_encode($log);
. That will send the data in JSON format to the client end. – nice_devresponse => this.logbook = response.data
should be(response) => { this.logbook = response.data})
? Note that if you are using.data
, you need to make sure that key is added when you are sending response to vue from your server. – nice_dev