【发布时间】:2021-09-15 07:18:45
【问题描述】:
我创建了一个页面,在其中列出了 BootstrapVue b 表中的所有项目。对于每个项目,我添加了删除项目的可能性。
当我使用 b-pagination 元素和 :per-page 属性激活分页时,页面上出现了意外行为。问题是它仅适用于第一页,但所有其他页面都获取第一页的数据。例如,如果总项目数为 10,而我每页显示 5 个项目,则显示接下来 5 个项目的第二页仍会尝试删除第一页项目。
<b-table
id="traffic-routes"
:fields="fieldsForTrafficRoutes"
:items="itemsForTrafficRoutes"
:per-page="perPageForTrafficRoutes"
:current-page="currentPageForTrafficRoutes"
>
<template v-slot:cell(action)="data">
<div class="d-flex align-items-center justify-content-end">
<a class="action-icon mr-2"
@click="removeRow(data.index)"
> Delete </a>
</div>
</template>
</b-table>
<b-pagination
v-model="currentPageForTrafficRoutes"
aria-controls="traffic-routes"
align="right"
:total-rows="
itemsForTrafficRoutes ? itemsForTrafficRoutes.length : 0"
:per-page="perPageForTrafficRoutes"
></b-pagination>
export default {
data() {
return {
perPageForTrafficRoutes: 5,
currentPageForTrafficRoutes: 1,
// ...
}
},
computed: {
...mapGetters([
'getAllTrafficRoutes',
]),
itemsForTrafficRoutes() {
return JSON.parse(JSON.stringify(this.getAllTrafficRoutes));
},
}
}
但是,我尝试使项目动态化:
itemsForTrafficRoutes() {
const foo = JSON.parse(JSON.stringify(this.getAllTrafficRoutes));
return foo.slice((this.currentPageForTrafficRoutes - 1) *
this.perPageForTrafficRoutes, this.currentPageForTrafficRoutes * this.perPageForTrafficRoutes
);
},
这将使每个页面的项目都是唯一的,它将只包含第一个上的前 5 个,然后在下一页更新到接下来的 5 个项目,但是,表格只显示第一页并且在第一个页面上是空的下一页,即使项目存在
【问题讨论】:
标签: javascript vue.js bootstrap-4 vuejs2 bootstrap-vue