fix(pagination): page count is not correct when item-count is 0

This commit is contained in:
07akioni 2021-07-10 01:20:21 +08:00
parent 199061c9b4
commit 47761e3605
4 changed files with 22 additions and 1 deletions

View File

@ -6,6 +6,10 @@
- `n-rate` add `allow-half` prop.
### Fixes
- Fix `n-pagination` page count is not correct when `item-count` is 0.
## 2.15.4 (2021-07-09)
### Feats

View File

@ -6,6 +6,10 @@
- `n-rate` 新增 `allow-half` 属性
### Fixes
- 修复 `n-pagination` `item-count` 为 0 时页数不对
## 2.15.4 (2021-07-09)
### Feats

View File

@ -125,7 +125,7 @@ export default defineComponent({
// item count has high priority, for it can affect prefix slot rendering
const { itemCount } = props
if (itemCount !== undefined) {
return Math.ceil(itemCount / mergedPageSizeRef.value)
return Math.max(1, Math.ceil(itemCount / mergedPageSizeRef.value))
}
const { pageCount } = props
if (pageCount !== undefined) return pageCount

View File

@ -5,4 +5,17 @@ describe('n-pagination', () => {
it('should work with import on demand', () => {
mount(NPagination)
})
it('props.itemCount', async () => {
const wrapper = mount(NPagination, {
props: {
itemCount: 1,
pageSize: 10
}
})
expect(wrapper.findAll('.n-pagination-item').length).toEqual(3)
await wrapper.setProps({
itemCount: 11
})
expect(wrapper.findAll('.n-pagination-item').length).toEqual(4)
})
})