Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/403.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript通过方法获取数据_Javascript_Laravel_Vue.js_Vuejs2 - Fatal编程技术网

Javascript通过方法获取数据

Javascript通过方法获取数据,javascript,laravel,vue.js,vuejs2,Javascript,Laravel,Vue.js,Vuejs2,我一直试图让这些代码正常工作,但我找不到正确的解决方案。请有人告诉我为什么这样做(加载数据加载),但新记录不会自动显示 <script> Vue.component('comments',{ template: '#comment-vue-template', data:() => { return { comments: [] } }, created: function(comments) { this.$

我一直试图让这些代码正常工作,但我找不到正确的解决方案。请有人告诉我为什么这样做(加载数据加载),但新记录不会自动显示

<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>

Vue.组件('注释'{
模板:“#注释vue模板”,
数据:()=>{
返回{
评论:[]
}
},
创建:函数(注释){
这是.http.get(“/comments”)
。然后(响应=>{
this.comments=response.body
});
设置超时(1000);
},
方法:{
getComments:函数(注释){
这是.http.get(“/comments”)
然后(响应=>{
this.comments=response.body
})
},
},
});
新Vue({
el:“#应用程序”,
});
下面的代码根本不起作用:-

<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>

Vue.组件('注释'{
模板:“#注释vue模板”,
数据:()=>{
返回{
评论:[]
}
},
创建:函数(注释){
这个.getComments();
},
方法:{
getComments:函数(注释){
这是.http.get(“/comments”)
然后(响应=>{
this.comments=response.body
});
setTimeout(this.getComments,1000);
},
},
});
新Vue({
el:“#应用程序”,
});
提前感谢

发现了我的错误

<script>
Vue.component('comments',{
  template: '#comment-vue-template',
  data:() => {
    return {
        comments: []
        }
    },
  created: function() {
    this.getComments();
  },
  methods: {
    getComments() {
      this.$http.get('/comments').then(response => {
        this.comments = response.body
      });
      setTimeout(this.getComments,1000);
    }
  }
});
new Vue({
  el:'#app',
});
</script>

Vue.组件('注释'{
模板:“#注释vue模板”,
数据:()=>{
返回{
评论:[]
}
},
已创建:函数(){
这个.getComments();
},
方法:{
getComments(){
这是.http.get('/comments')。然后(response=>{
this.comments=response.body
});
setTimeout(this.getComments,1000);
}
}
});
新Vue({
el:“#应用程序”,
});

开发人员控制台中是否有任何错误?在第二个示例中,您在
之前缺少了一个
,然后
@craig_h发现了我的错误。非常感谢。