【发布时间】:2020-08-19 07:22:41
【问题描述】:
我有多个视图,我想保存每个视图的状态,这样用户就不必再做同样的事情了。
在其中一个上,我有一个表,我使用 bootstrap-pagination 组件进行分页,因此当用户更改页面时,我将请求发送到服务器以获取新数据。我在 Vuex 中存储排序和过滤参数,效果很好。
但是当我想像这样保存当前页面时,每次我更改视图并返回时,bootstrap-pagination 都会将其更改为 1。 是否可以防止这种行为?
以下是 HTML 代码:
<b-pagination v-if="currentPage!=-1"
v-model="currentPage"
:total-rows="totalRows"
:per-page="perPage"
aria-controls="my-table"
pils
align="center"
class="ml-auto mr-auto"
></b-pagination>
和javascript中的代码:
data: function () {
return {
...
currentPage: this.$store.state.currentPage,
...
}
},
...
watch: {
currentPage: function(){
this.$store.commit('updateCurrentPage', this.currentPage);
this.getData();
},
}
【问题讨论】:
标签: vue.js vuex bootstrap-vue