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发现了我的错误。非常感谢。