我能够在发布数据,喜欢发布,评论发布后查看所有数据,而无需刷新页面,但是在vuejs中使用无限滚动之后,无限滚动工作得很好,但是喜欢,评论,发布后却看不到发布。 .i必须每次刷新以查看帖子上的评论/赞。我怎么能看到没有刷新页面的准时?请帮助我解决这个问题
el: '#app',
data() {
return {
posts: [ ],
page: 1,
};
},
created(){
this.allposts();
},
}
methods:{
Before using infinite scroll on app.js
allposts(){
axios.get('http://localhost/project/posts')
.then((response) => {
this.posts = response.data;
Vue.filter('myOwnTime', function(value){
return moment(value).fromNow();
});
})
.catch(() => {
console.log('handle server error from here');
});
},
After using vue infinite scroll
https://peachscript.github.io/vue-infinite-loading/guide/start-with-hn.html
allpost($state) {
axios.get('http://localhost/project/posts', {
params: {
page: this.page,
},
})
.then(({ data }) => {
if (data.data.length) {
this.page += 1;
this.posts.push(...data);
Vue.filter('myOwnTime', function(value){
return moment(value).fromNow();
});
$state.loaded();
} else {
$state.complete();
}
});
},
like function is same for both
likePost(id){
axios.get('http://localhost/project/posts' + id)
.then(response => {
console.log(response);
this.allposts();//
})
.catch(function (error) {
console.log(error);
});
},
} ```