vue element Pagination分页当前页数bug

Pagination

问题:从详情页返回设置了currentPage失效,第一页高亮

情况:
1.在第二页点击详情进入,进入是currentPage为2,页标2高亮
在这里插入图片描述
2.从详情页回来设置currentPage为2,还是1高亮。(调用了之前的搜索数据重新请求了数据,不然照初始化进入会呈现第一页的内容)
在这里插入图片描述

//html
<div class="block">
  <el-pagination
    :current-page.sync="currentPage"
    :page-size="5"
    layout="total, prev, pager, next"
    :total="TransApplyList.total"
    @prev-click="prevPage"
    @next-click="nextPage"
    @current-change="nowPage"
  ></el-pagination>
</div>
//选择页码跳转触发函数,在mounted钩子函数里面
nowPage(Page) {
  this.currentPage = Page;
  this.queryok.pageNum = this.currentPage;
  this.$axios
    .post(
      "",
      this.queryok,
    )
    .then(response => {
    })
    .catch(error => {
    });
},
//从详情返回进去该页面执行的函数
this.query1ok = ...;//获取了搜索条件
this.currentPage = ...;//设置当前页数
this.nowPage(this.currentPage)
console.log("this.currentPage:"+this.currentPage)

从第二页的详情回来打印的是this.currentPage:2

高亮部分和currentPage不痛会导致一些bug
我试过的,加入一共有三页,我从第二页进入详情,出来后高亮在第一页,但是请求和获取到的数据是第二页,console下来的currentPage也是2。点击了一次下一页箭头,请求和获取到的数据是第二页,console下来的currentPage也是2,都不变。但是再点一次请求和获取到的数据是第一页,console下来的currentPage也是1.还没有找到这个bug原因所在。


解决:给一个v-if让它获取到了currentPage在渲染Pagination组件

//html
<div class="block"  v-if="pageshow">
  <el-pagination
    :current-page.sync="currentPage"
    :page-size="5"
    layout="total, prev, pager, next"
    :total="TransApplyList.total"
    @prev-click="prevPage"
    @next-click="nextPage"
    @current-change="nowPage"
  ></el-pagination>
</div>
//初始化里面
pageshow:false,
//在mounted最后面加上(获取currentPage就在mounted里面)

 this.$nextTick(() => {
     this.pageshow = true
 })

这样返回currentPage是多少页码高亮就是那个

你可能感兴趣的:(element,UI)