page.vue 961 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <template>
  2. <div id="page">
  3. <van-pagination v-model="currentPage" @change="changePage" :total-items="total" :items-per-page="limit" :show-page-size="5" force-ellipses />
  4. </div>
  5. </template>
  6. <script>
  7. import { mapState, createNamespacedHelpers } from 'vuex';
  8. export default {
  9. name: 'page',
  10. props: {
  11. total: { type: Number },
  12. limit: { type: Number, default: () => 5 },
  13. },
  14. components: {},
  15. data: function() {
  16. return {
  17. currentPage: 1,
  18. };
  19. },
  20. created() {},
  21. methods: {
  22. changePage(page) {
  23. this.$emit('search', { skip: (page - 1) * this.limit });
  24. },
  25. },
  26. computed: {
  27. ...mapState(['user']),
  28. },
  29. metaInfo() {
  30. return { title: this.$route.meta.title };
  31. },
  32. watch: {
  33. total: {
  34. deep: true,
  35. immediate: true,
  36. handler(val) {
  37. // 查询条件,重置页码
  38. if (val) this.$set(this, `currentPage`, 1);
  39. },
  40. },
  41. },
  42. };
  43. </script>
  44. <style lang="less" scoped></style>