pagekit / vue-resource

The HTTP client for Vue.js
MIT License
10.09k stars 1.6k forks source link

Reload code after $http.get('/') #666

Open dianavillegas opened 6 years ago

dianavillegas commented 6 years ago

Is there another way to reload the request after it has loaded successfully? We were using setTimeout to reload the code however the response data is fluctuating or is not accurate for every load.

`fetchFinished: function(){

        var vm = this;
        var finishedtodays = [];
        var pendingsss = [];

       vm.$http.get('/test').then(function(response){

         this.finishedtoday = [];
         this.pendingtasks = [];

          var name = response.body.daily;
          var name2 = response.body.pending;
          vm.tablecounts = name;
          console.log('test1')
          //for finsihed today
          name.forEach(function(key, value){
            var count = key.daily_count;
            var name = key.name

            finishedtodays.push({"name": name.split(" ")[0], "count": count});

          });

          //for pending tasks

           name2.forEach(function(key, value){
            var firstname = key.name
            var count = key.count

            pendingsss.push({"name": firstname.split(" ")[0], "count": count});

           });
          vm.finishedtoday = finishedtodays;
          vm.pendingtasks = pendingsss;
          //for fetching all
          vm.allcounts = response.body.allcount;

          console.log("Test run");            

        }).catch(function(error){
        });

       setTimeout(this.fetchFinished.bind(this), 1000);
       //setInterval(this.fetchFinished.bind(this), 10000); 
      // this.$forceUpdate();
      }`