清新組件庫:http://ifresh-ui.yating.online/
源碼地址:https://github.com/Chenyating/iFresh-ui
page組件遇到的問題
返回的頁面數問題
當頁面過於長的時候,可以這樣顯示。
- 頁面數小於等於6,就默認遍歷1-6
- 頁面數大於6時,如果當前頁小於2或者大於總頁數-2:返回數組爲[1,2,3,……,page-1,page]
- 頁面數大於6時,如果當前頁爲中間值:返回數組爲[……,current-1,current,current+1,……]
// 頁數小於6,顯示頁數
if (pageNumber <= 6) {
return pageNumber
} else {
if (this.currentPage <= 2 || this.currentPage >= pageNumber - 2) {
return [1, 2, 3, '…', pageNumber - 2, pageNumber - 1, pageNumber]
} else {
return ['…', this.currentPage - 1, this.currentPage, this.currentPage + 1, '…']
}
}
向上取整
Math.ceil()