-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Page分页@on-page-size-change之前会调用@on-change, 执行了两次post #759
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
Comments
会先调用@on-Change回到第一页,再调用@on-page-size-change改变分页显示数量。这样会先拿一遍第一页当前的pageSize的数据,再拿一遍第一页改变后的pageSize的数据。求教该怎么解决? |
Bug Approved.
|
Validate Code: 插件中的this.currentPageSize还没props给实例已经调用了this.changePage,this.changePage则传给监听器一次回调 方案: 更改node_modules/iview/src/page中的onSize
这样实例上可以根据需求自行changePage @Yougoss 临时可以修改node_modules/iview/dist/iview.js#12838 |
当前如果不是第一页,切换每页条数时就会到第一页,自如要触发on-change。业务中只需要监听 on-change 就可以 |
@icarusion 只监听on-change的话,改变每页条数的话,不会触发on-change了,导致数据展示错误。 |
@icarusion 当切换pageSize时,只监听on-change会有会有两种情况:
建议不管currentPage 是否等于1 都触发on-change |
建议从框架层面去掉onSize (pageSize)函数中的this.changePage(1); |
改变pageSize同时触发changePage 我的解决方法: |
我的解决方法是: <Page :total="totalResults" :page-size="pageSize" @on-change="changePage" @on-page-size-change="changePageSize" show-sizer show-elevator show-total></Page> data () {
return {
tableData: this.requestData(1, 10),
pageIndex: 1,
pageSize: 10,
totalResults: 0
}
},
methods: {
requestData (currentPage, pageSize) {
......
},
changePage (currentPage) {
this.tableData = this.requestData(currentPage, this.pageSize);
},
changePageSize (pageSize) {
this.pageSize = pageSize;
}
...
} |
不在第一页的时候,触发on-page-size-change的同时触发on-change真的是很坑爹啊. |
有这样一个方案可以解决: <template>
<div>
<Page @on-change="listPageChange" @on-page-size-change="listPageSizeChange" />
</div>
</template>
<script>
export default {
data() {
return {
isGetList: true
}
},
methods: {
listPageChange(e) {
if (this.isGetList) {
// get list data
}
},
listPageSizeChange(e) {
this.isGetList = false
// get list data
// some code
this.isGetList = true // 获取数据完成后设置为 true
}
}
}
</script>
<style>
</style>
|
/* 扩展iview的Page组件,拦截默认行为==>pageSize变化时,也会触发page-change事件 */ export default { 使用mixins拦截默认的onSize事情:去掉调用触发page-size的方法 |
在changePageSize 事件中判断一下 pageNum, 如果pageNum == 1 就 触发事件. <Page v-bind="pagination" :pageSize="pageOptions.pageSize" :total="dataList.total" :current.sync="pageOptions.pageNum" @on-change="changePageNum" @on-page-size-change="changePageSize"></Page>
computed: {
page() {
return {
pageSize: this.pageOptions.pageSize,
pageNum: this.pageOptions.pageNum
}
},
},
methods: {
// 修改页数
changePageNum(){
this.$emit('handlePageSize', this.page)
},
// 修改每页大小
changePageSize(size){
this.pageOptions.pageSize = size
this.pageOptions.pageNum === 1 && this.changePageNum()
},
} |
Uh oh!
There was an error while loading. Please reload this page.
iView 版本号
2.0.0-rc.9
操作系统/浏览器 版本号
macOS/Chrome 56
Vue 版本号
^2.2.2
问题现象,以及你期望的结果是怎样的?
Page 分页@on-page-size-change之前会调用@on-Change,
会先调用@on-Change回到第一页,再调用@on-page-size-change改变分页显示数量。这样会先拿一遍第一页当前的pageSize的数据,再拿一遍第一页改变后的pageSize的数据
The text was updated successfully, but these errors were encountered: