0

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

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

1 Answer 1

1

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...

Sign up to request clarification or add additional context in comments.

2 Comments

@Kendall There is vue-paginate component, just let you know github.com/TahaSh/vue-paginate :)
@Belmin tried that but was not able to implement it properly. I am using table rows...and his uses list items

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.