samedi 27 juillet 2019

How to load data after liking post in vuejs(laravel) without refreshing page using vuejs infinite scroll?

i am able to see all the data after posting data, liking post , commenting on post without page refresh but after using infinite scroll in vuejs, infinite scroll working perfectly fine but not able to see post after liking ,commenting , posting..i have to refresh every time to see the comment/like on post. How can i see ontime like without page refresh ?Please help me figure this out anyone

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);
          });
   },


} ```
How can i see ontime like without page refresh ?Please help me figure this out

via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire