page-size 每頁顯示條目個數
current-page 當前頁數
total 數據總數
current-change【currentPage 改變時會觸發】
切換分頁時會先加載,等在接口數據,接口返回,加載會關閉(在獲取接口數據完畢哪里加上this.loading=false),前提是在數據哪里綁定 v-loading=“loading”
例如: <el-table :data="list" border style="width: 100%" v-loading="loading"></el-table>
<el-paginationbackgroundlayout="prev, pager, next"align="right"style="padding: 10px":page-size="pageParams.pagesize":current-page="pageParams.page":total="pageParams.total"@current-change="changePage"></el-pagination>
<script>
import { getRoleList } from "@/api/role.js";
export default {name: "Role",data() {return {loading: false,pageParams: {pagesize: 5, //每頁多少條page: 1, //當前頁碼數total: 0,},};},created() {this.getRoleList();},methods: {async getRoleList() {//先解構了rows,再解構了total //await getRoleList(this.pageParams); 把const { rows, total } = await getRoleList(this.pageParams);this.list = rows;this.pageParams.total = total;},//點擊時觸發,使頁碼變化changePage(newPage) {this.loading = true;//變化了頁碼,把最新的數據賦值給 this.pageParams.page this.pageParams.page = newPage;//在頁碼發生變化之后,再發一次請求,更新數據this.getRoleList();},},
};
</script>