Cat*_*nin 5 frontend vue.js vue-component vuejs2 vuetify.js
我有一个v-data-table,正在尝试向其中添加分页。我在这里跟随了示例文档,看不到我在做什么错。创建我的组件后,它将调用我的后端以填充项目列表。然后将其传递到数据表。
我也有一个搜索栏,如果我输入任何内容,那么页面编号就会弹出。
的HTML
<v-data-table
:headers="headers"
:items="incidents"
:search="search"
:pagination.sync="pagination"
hide-actions
class="elevation-1"
item-key="incident_number"
>
</v-data-table>
/* table row html in between */
<div class="text-xs-center pt-2">
<v-pagination v-model="pagination.page" :length="pages" </v-pagination>
</div>
Run Code Online (Sandbox Code Playgroud)
JS
我有一个计算出的属性,可以像示例中那样计算出页码。
computed: {
pages ()
{
if (this.pagination.rowsPerPage == null || this.pagination.totalItems == null)
{
return 0
}
return Math.ceil(this.pagination.totalItems / this.pagination.rowsPerPage)
},
}
Run Code Online (Sandbox Code Playgroud)
解决了问题。当我在搜索栏中输入某些内容时它就会起作用,所以我注意到 Vue 正在发出一个事件。update:pagination其中有一个名为的键值totalItems,它被设置为0页面加载,但是当我在搜索栏中输入某些内容时,它之后会有一个值。
页面加载时
为了解决这个问题,当我的后端返回带有表数据的响应时。我将 的totalItems长度设置为表中条目数的长度。
this.incidents = response.data['incidents']
this.pagination.totalItems = this.incidents.length
Run Code Online (Sandbox Code Playgroud)
通过修复或在搜索栏中输入
不确定这是否是 Vuetify v-data-table 的错误或问题。
| 归档时间: |
|
| 查看次数: |
2803 次 |
| 最近记录: |