Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

封装的Pagination点击切换每页数量返回错误的BUG #2018

Closed
AJhinChen opened this issue May 6, 2019 · 1 comment
Closed

封装的Pagination点击切换每页数量返回错误的BUG #2018

AJhinChen opened this issue May 6, 2019 · 1 comment
Labels
Inactivity Closing for inactivity. need repro 🔎

Comments

@AJhinChen
Copy link

AJhinChen commented May 6, 2019

Bug report(问题描述)

你好,我在学习你Demo的时候发现使用本地数据做分页切换每页数量时返回的PageSize-即limit参数的值时,拿到的都是上一次的值

Steps to reproduce(问题复现步骤)

  1. [import Pagination from '@/components/Pagination' // Secondary package based on el-pagination]引用封装后的组件
  2. 配置[:page.sync="currentPage" :limit.sync="pageSize"]
  3. [点击页面控件的‘30条/页’等,切换页签,获取paheSize的值]

解决方案

  1. 我分析的原因是:在封装代码中-handleSizeChange方法的执行顺序优先于computed的pageSize的set,get方法,因此在this.$emit('pagination', { page: this.currentPage, limit: val })之后才返回了当前真正的limit值
  2. 粗暴的解决方法:将this.$emit('pagination'..)方法放到set方法中
    3.代码:
computed: {
    currentPage: {
      get() {
        return this.page
      },
      set(val) {
        this.$emit('update:page', val)
      }
    },
    pageSize: {
      get() {
        return this.limit
      },
      set(val) {
        this.$emit('update:limit', val)
        this.$emit('pagination', { page: this.currentPage, limit: val })//移到此处
      }
    }
  },
  methods: {
    handleSizeChange(val) {
      //此处移除
      if (this.autoScroll) {
        scrollTo(0, 800)
      }
    },
    handleCurrentChange(val) {
      this.$emit('pagination', { page: val, limit: this.pageSize })
      if (this.autoScroll) {
        scrollTo(0, 800)
      }
    }
  }

Screenshot or Gif(截图或动态图)

Link to minimal reproduction(最小可在线还原demo)

Other relevant information(格外信息)

  • Your OS: Mac
  • Node.js version: npm 6.5.0
  • vue-element-admin version: master-release4.1.0
@PanJiaChen
Copy link
Owner

并没有能重现。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Inactivity Closing for inactivity. need repro 🔎
Projects
None yet
Development

No branches or pull requests

2 participants