Reputation: 169
I am using am new to laravel(5.2) and vue. I am trying to pass data to a view from a database. It appears that my right route is fine and I get some json data response but I am having trouble logging the data to console or my view. Kindly let me know what I am doing wrong.
Here is my ShowEvent component stored in a .vue file
<template>
<div class="events_list">
<h1> My Events </h1>
<ul class="list-group">
<li class="list-group-item" v-for="event in list">
{{ event.body}}
</li>
</ul>
</div>
</template>
<script>
export default {
data: function () {
return {
list: []
};
},
created: function(){
this.fetchEventsList();
},
methods: {
fetchEventsList: function () {
this.$http.get('/api/events', function(data){
console.log(data);
});
},
delete: function(event) {
this.list.$remove(event);
}
}
}
Here is my main.js file
import Vue from 'vue';
import VueResource from 'vue-resource';
Vue.use(VueResource);
import ShowEvent from './components/ShowEvent.vue';
new Vue({
el: '#app',
components: {ShowEvent: ShowEvent},
ready(){
alert("Ready to go!, Show Events");
}
});
And this is the the view file
<!DOCTYPE html>
<html>
<head>
<title>Eventer</title>
</head>
<body>
<div id="app" class="container">
<show-event>
</show-event>
</div>
<script src="/js/main.js"></script>
</body>
</html>
Upvotes: 0
Views: 100
Reputation: 153
Replace your call with:
this.$http.get('/api/events').then((response) => {
console.log(response.data)
}, (error) => {
console.log(error)
})
Check the docs for more info
Upvotes: 2