私はlaravel(5.2)とvueを初めて使用しています。データベースからビューにデータを渡そうとしています。私の正しいルートは問題ないようで、json データの応答を受け取りますが、データをコンソールまたはビューに記録するのに問題があります。私が間違っていることを教えてください。
これが .vue ファイルに保存された私の ShowEvent コンポーネントです
<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>