【问题标题】:Pagination links appear as dots in vue分页链接在 vue 中显示为点
【发布时间】:2020-04-23 01:25:46
【问题描述】:

我正在尝试在 vue 中实现分页。我在这里面临的问题是分页链接显示为点,如附图所示。出现的分页链接数是正确的。我可以使用分页链接 () 上的侧导航箭头在不同的页面上导航。我无法弄清楚我哪里出错了。帮我弄清楚这个问题。

<template>
  <v-app class="abilities">
    <v-data-table
      :headers="headers"
      :items="users"
      hide-actions
      class="user-table"
      v-bind:pagination.sync="pagination"
    >
      <template slot="items" slot-scope="props">
        <td>{{ props.item.date }}</td>
        <td>{{ props.item.description }}</td>
      </template>
      <template slot="no-data" >
        <v-alert id='no-data' :value="true" color="error" icon="warning">
          No User Yet
        </v-alert>
      </template>
    </v-data-table>
    <v-layout row wrap v-if="this.users.length > 5">
      <v-flex xs12>
        <div class="user-pagination">
          <v-pagination v-model="pagination.page" :length="pages"></v-pagination>
        </div>
      </v-flex>
    </v-layout>
  </v-app>
</template>


<script>
export default {
  data: function() {
    return {
      pagination: {
        rowsPerPage: 5,
        page: 1
      },
      headers: [
        {
          text: 'Date',
          sortable: false,
          value: 'name'
        },
        {
          text: 'Description',
          sortable: false,
          value: 'name'
        },
      ],
      users: [],
    };
  },
  created: function() {
    var that = this;

    this.fetchUsers();
  },
    computed: {
    pages () {
      return this.pagination.rowsPerPage ? Math.ceil(this.users.length / this.pagination.rowsPerPage) : 0
    }
  },
  methods: {
    fetchUsers() {
      var url = '/users.json?';
      this.$axios
        .get(url)
        .then(response => {
          let data = response.data;
          let users = [];
          data.map((user, index) => {
            let expandedData = user;

            users.push(expandedData)
          });

          this.users = users;
        });
    }
  }
};
</script>

【问题讨论】:

  • 如果您使用浏览器 F12 Inspect,那么 DOM 中的 ... 值是否显示为数字或相同的 ... ?这似乎是ellipsis 文本大小写(可能在服务器或前端)
  • 此问题已在更改浏览器大小时得到修复。知道如何解决这个问题吗?
  • 我认为这很可能是 Vuetify 的噱头:“使用 length 属性可以设置 v-pagination 的长度,如果页面按钮的数量超过父容器,就会截断列表。” vuetifyjs.com/en/components/paginations
  • 我已经在使用 length 属性了。

标签: javascript vue.js pagination vuetify.js


【解决方案1】:

问题出在计算属性上,在某些情况下它返回 InfinityNaN

this.pagination.rowsPerPage0 你正在做的事情:

return Math.ceil(this.users.length / 0)

返回infinity

this.users.length0 你有:

return Math.ceil(0 / 0)

返回NaN

所以你得到...

应该这样做:

computed: {
  pages () {
    return this.pagination.rowsPerPage && this.users.lenght!= 0 ? Math.ceil(this.users.length / this.pagination.rowsPerPage) : 0
  }
},

【讨论】:

  • 还是一样。我尝试了您的解决方案,但没有解决。
  • 仍然没有变化。同样的问题。
  • 其实是我的错。我正在使用带有 v-tabs 的分页。向 v-tabs 添加惰性解决了这个问题
猜你喜欢
  • 2013-04-07
  • 1970-01-01
  • 2017-07-18
  • 2012-07-30
  • 2022-01-18
  • 1970-01-01
  • 2017-10-18
  • 2017-12-01
  • 1970-01-01
相关资源
最近更新 更多