vue+element 分頁bug
阿新 • • 發佈:2021-02-03
技術標籤:elementuivueelementuipaginationchrome前端
vue+elementPagination 分頁 第二頁刪除最後一條資料自動跳到上一頁
問題:當資料較多時使用element中的分頁功能,在刪除第二頁的最後一條資料時,當前頁數轉成了上一頁,可是頁面資料並沒有跳轉到上一頁
1.刪除最後一條資料之前(當前頁數為第二頁)
2.刪除最後一條資料之後(當前頁數轉為第一頁,可是頁面並沒有跳轉到第一頁,而是顯示暫無資料)
解決辦法:
<!--分頁--> <div class="page"> <el-pagination :page-sizes="[10, 20, 30, 50]" :page-size="queryForm.limit" :total="queryForm.total" :current-page="queryForm.current" layout="total, sizes, prev, pager, next, jumper" prev-text="上一頁" next-text="下一頁" background @size-change="handleSizeChange" @current-change="handleCurrentChange" /> </div> // data data() { return { queryForm: { current: 1, // 當前第幾頁 limit: 10, // 每一個頁面限制10條資料 total: 0 // 資料總數 }, } }, // methods methods:{ // n頁最後一條資料刪除之後自動前往上一頁 returnPage() { console.log('刪除之後的總頁數', this.queryForm.total - 1) if (this.queryForm.total - 1 === (this.queryForm.current - 1) * this.queryForm.limit && this.total !== 0) { this.queryForm.current-- // 當前頁減一,跳轉到上一頁 this.close() // 關閉刪除操作的彈窗--並重新請求資料 } this.close() // 關閉刪除操作的彈窗--並重新請求資料 }, } //在刪除資料成功之後呼叫this.returnPage()即可