我正在使用laravel(5.2)和vue。我正在尝试将数据传递到数据库中的视图。看起来我的正确路线很好,我得到一些json数据响应,但我无法将数据记录到控制台或我的视图。请让我知道我做错了什么。
这是我的ShowEvent组件存储在.vue文件
中<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);
}
}
}
这是我的main.js文件
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");
}
});
这是视图文件
<!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>
答案 0 :(得分:2)
将来电替换为:
this.$http.get('/api/events').then((response) => {
console.log(response.data)
}, (error) => {
console.log(error)
})
Check the docs了解更多信息