【发布时间】:2017-03-12 12:22:44
【问题描述】:
我一直试图让这些代码工作,但我找不到正确的解决方案。请有人告诉我为什么这样做(加载时加载数据)但不会自动显示新记录。
<script>
Vue.component('comments',{
template: '#comment-vue-template',
data:() => {
return {
comments: []
}
},
created: function(comments) {
this.$http.get('/comments')
.then(response => {
this.comments = response.body
});
setTimeout(1000);
},
methods: {
getComments: function(comments) {
this.$http.get('/comments')
then(response => {
this.comments = response.body
})
},
},
});
new Vue({
el:'#app',
});
</script>
下面的代码根本不起作用:-
<script>
Vue.component('comments',{
template: '#comment-vue-template',
data:() => {
return {
comments: []
}
},
created: function(comments) {
this.getComments();
},
methods: {
getComments: function(comments) {
this.$http.get('/comments')
then(response => {
this.comments = response.body
});
setTimeout(this.getComments,1000);
},
},
});
new Vue({
el:'#app',
});
</script>
提前致谢
【问题讨论】:
-
您的开发者控制台中是否有任何错误?在您的第二个示例中,您在
then之前缺少一个. -
@craig_h 发现了我的错误。谢谢
标签: javascript laravel vue.js vuejs2