lokyoung / vuejs-paginate

A Vue.js(v2.x+) component for creating pagination.
MIT License
779 stars 171 forks source link

Multiple paginate components in one view #36

Closed ooduor closed 7 years ago

ooduor commented 7 years ago

I tried putting 2 <paginate/> at the top and bottom of my listing and using the same shared variables but when I click page 2 on the top one and scroll to the bottom one, it will still be one page behind.

lokyoung commented 7 years ago

Hello @highPriestLOL , You should set the selected page by $refs. You can check the following code.

<template>
  <div>
    <paginate
      :page-count="20"
      :margin-pages="2"
      :page-range="4"
      :initial-page="0"
      :container-class="'pagination'"
      :click-handler="clickCallback"
      ref="paginate1"
    ></paginate>
    <paginate
      :page-count="20"
      :margin-pages="2"
      :page-range="4"
      :initial-page="0"
      :container-class="'pagination'"
      :click-handler="clickCallback"
      ref="paginate2"
    ></paginate>
  </div>
</template>

<script>
export default {
  methods: {
    clickCallback(page) {
      this.$refs.paginate1.selected = this.$refs.paginate2.selected = page - 1;
    }
  }
}
</script>
ooduor commented 7 years ago

Perfect. Works!