I have a vue component for which I get paginated data from api.

What I want to do is update the iterated list using a smaller pagination total...thus in my vue component template

<td v-for="item in listItems">......
</td>

and in the script

    {
  data (){ return { items:[]; pageSize:5, page:1 } // items is 20 in total; pageSize is 5 per page
  computed :{
    listItems: function(){ 
      var arr = [];
      while (i < this.pageSize) { 
        arr.push(this.items[i + (this.page * this.pageSize)]); 
       i++;
      } 
      return arr ;
      } 
    }, 
    methods:{ 
        getDATA: function(){ this.$http.get().then(response => {
                  this.items = response.data.data; // array of data objects
              }); 
          }
        }
  }

but i get an empty array/ i'm guessing I can't just iterate like a normal array

share|improve this question
1  
Your code is incomplete or incorrect. Where do you actually return anything for listItems? – David L Nov 28 at 22:05
1  
Please provide actual code.This thing you posted doesn't tell anything. – Belmin Bedak Nov 28 at 22:09
1  
What console says ? I think you are missing this keyword on page, pageSize and items. – Belmin Bedak Nov 28 at 22:21
    
@DavidL I updated the question – Kendall Nov 28 at 22:48

If I understand you correctly this might be what you are looking for

export default {
  {
    data () { 
      return { 
        items: [],
        page: 1,
        pageSize: 1
      }
    },
    computed: {
      listItems() => { 
        while (i < this.pageSize) { 
          this.items[i + (this.page * this.pageSize)]; 
        }
      } 
    }
  }
}

But I'm not sure what you're trying to do so it's the best I can do with limited information, and it looks like you're trying to set data in a computed method, which I'm not 100% sure you can do...

share|improve this answer
    
Sorry I updated question – Kendall Nov 28 at 22:22
    
@Kendall There is vue-paginate component, just let you know github.com/TahaSh/vue-paginate :) – Belmin Bedak Nov 28 at 22:24
    
@Belmin tried that but was not able to implement it properly. I am using table rows...and his uses list items – Kendall Nov 28 at 22:34

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.