解决element 分页组件,搜索过后current-page 绑定的数据变了,但是页面当前页码并没有变的问题

bug:vue和element实现的后台分页,当前是第二页,点击搜索,强制设置current-page为1,但是当前页还是第二页没有改变只是数据变了。

绑定一个变量

  • 页面 el-pagination v-if="pageshow"

  <el-pagination v-if="pageshow"  
                background
                @current-change="handleCurrentChange"
                style="float:right;margin: 10px"
                :page-size="10"
                layout="prev, pager, next,total"
                :total="totalCount">
        </el-pagination>

使用v-if绑定数据,当每次搜索的时候就注销掉前一个分页Dom,画面刷新完毕后,渲染一个同样的分页,重新渲染必须放到$nextTick中,这样在使用分页就不会出现问题了。

 query(val) {
                val ? this.form.currentPage = val : this.form.currentPage = 1        
                if(!val){
                    this.pageshow = false
                    this.$nextTick(() => {
                        this.pageshow = true
                    })
                }
                 请求数据.......
                
            },
不停学习,热爱是源源不断的动力。
原文地址:https://www.cnblogs.com/ximenchuifa/p/15006647.html