最近在一直在做關(guān)于表格頁面,遇到了一個小問題舞竿,“table列表刪除當(dāng)前頁的數(shù)據(jù)顯示前一頁”廓八,鑒于它有多種可能性奉芦,記錄一下。
第一種
這種方法是最常見也是最簡單的只需要在刪除成功的回調(diào)里面寫一下的方法就可以了
if (this.total % this.pageSize === 1) { // 表格總數(shù)量 % 行數(shù) 余出的就是當(dāng)前頁有幾個 ????const lastPage = (this.total + this.pageSize - 1) / this.pageSize // (表格總數(shù)量 +行數(shù) -1) / 行數(shù)
? ? if (this.currentPage === lastPage) { // 當(dāng)前頁 === (表格總數(shù)量 +行數(shù) -1) / 行數(shù) ????????this.currentPage = this.currentPage - 1 // 減去一頁就是前一頁
?????}
}
第二種
一個是點擊全部的剧蹂,一個點擊是單選的声功,在這兩個事件中分別觸發(fā)不一樣的判斷
// 在點擊全部復(fù)選框時
if (this.currentPage !== 1) {
?????this.currentPage = this.currentPage - 1
}
// 點擊單選復(fù)選框時
if (this.total % this.pageSize === 1) {
?????const lastPage = (this.total + this.pageSize - 1) / this.pageSize
?????if (this.currentPage === lastPage) {
?????????this.currentPage = this.currentPage - 1
?????}
}
第三種
這種其實跟第二種相似但是又很不相似,他還多了一種選擇多個在移除
// this.fundCodeSelectList 這個變量是個數(shù)組宠叼,里面放的是要移除的代碼code
if (this.currentPage !== 1 && this.fundCodeSelectList.length == 1) { // 如果單選 執(zhí)行
?????if (this.total % this.pageSize === 1) {
?????????const lastPage = (this.total + this.pageSize - 1) / this.pageSize
? ? ? ? ?if (this.currentPage === lastPage) {
?????????????this.currentPage = this.currentPage - 1
?????????}
?????}
} else if (this.fundCodeSelectList.length > 1 && this.fundCodeSelectList.length < this.pageSize && this.fundCodeSelectList.length !== this.total % this.pageSize) {
?????this.fundCodeSelectList = [] this.getGetFundFollowList()
} else {
????// 如果多選 執(zhí)行
?????if (this.currentPage !== 1) {
?????????this.currentPage = this.currentPage - 1
?????}
?}