一. 創(chuàng)建Pagings.vue文件(子組件)
<template>
<div class="pagetion">
<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" background :current-page="offset"
:page-size="pageSize" :page-sizes="[5,10,20,30]" layout=" prev, pager, next, sizes,jumper"
:total="total">
</el-pagination>
</div>
</template>
<script type="text/ecmascript-6">
export default {
data() {
return {
}
},
props: {
total:{ // 總條目數(shù)
type: Number,
default: 1 //默認(rèn)值
},
pageSize:{ //每頁(yè)顯示條目個(gè)數(shù)
type: Number,
default: 1
},
offset:{ //當(dāng)前頁(yè)數(shù)
type: Number,
default: 1
},
},
methods: {
handleSizeChange(val) { //pageSize 改變時(shí)會(huì)觸發(fā)
this.$emit('handleSizeChangeSub', val);
},
handleCurrentChange(val) { //currentPage 改變時(shí)會(huì)觸發(fā)
this.$emit('handleCurrentChangeSub', val);
}
},
}
</script>
二.在需要頁(yè)面(父組件)引入Pagings.vue文件
<template>
<div>
<!-- 分頁(yè) -->
<div >
<Pagings :total="total" :offset="oAssEquipmentDto.offset" :pageSize="oAssEquipmentDto.pageNumber"
@handleSizeChangeSub="handleSizeChange" @handleCurrentChangeSub="handleCurrentChange"></Pagings>
</div>
</div>
</template>
<script>
import Pagings from '../../components/Pagings/index.vue'
import http from "../../service/power.js"; //不需要
const power = new http(); //不需要
export default {
data() {
return {
oAssEquipmentDto: {
offset: 1,
pageNumber: 5,
},
total: 1, //總條數(shù)
};
},
components: {
Pagings
},
created() {
this.power();
},
methods: {
power() {
//請(qǐng)求接口
power.powerStationList(this.oAssEquipmentDto).then(res => {
this.total = res.data.data.totalNum
this.oAssEquipmentDto.offset = res.data.data.pageNum;
this.oAssEquipmentDto.pageNumber = res.data.data.pageSize;
});
},
handleSizeChange(val) {
this.oAssEquipmentDto.pageNumber = val;
this.power();
},
handleCurrentChange(val) {
this.oAssEquipmentDto.offset = val;
this.power();
},
}
};
</script>
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。