如何在vuejs-paginate中手动设置pageCount?

时间:2017-03-28 17:33:15

标签: pagination vue.js paginate

我的HTML:

<paginate
        :pageCount="max"
        :containerClass="'pagination'"
        :clickHandler="redirectToPage"
        :force-page="selectedPage">
</paginate>

max 是来自 vuex 的getter。当paginate加载max = undefined时,我需要在更改value max后设置 pageCount

在官方文档中只有静态值: enter image description here

1 个答案:

答案 0 :(得分:2)

Belmin Bedak 的评论考虑在内,此处正在使用v-if让其等待pageCount加载。在测试中,我发现更新pageCount按预期工作:更新可用页数。

&#13;
&#13;
vm = new Vue({
  el: '#app',
  data: {
    max: null
  },
  components: {
    paginate: VuejsPaginate
  },
  methods: {
    clickCallback: function(page) {
      console.log(page);
    }
  },
  mounted() {
    // Pretend we're getting from vuex
    setTimeout(() => {
      this.max = 7;
    }, 1000);
  }
});
&#13;
<link href="//cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.css" rel="stylesheet" />
<script src="//cdnjs.cloudflare.com/ajax/libs/vue/2.2.6/vue.min.js"></script>
<script src="https://unpkg.com/vuejs-paginate@0.8.0"></script>
<div id="app">
    <paginate v-if="max"
      :page-count="max"
      :container-class="'pagination'"
      :click-handler="clickCallback">
    </paginate>
    <div v-else>
    Loading...
    </div>
</div>
&#13;
&#13;
&#13;