1.paginación del elemento (vue2)
1) Encapsular componentes de paginación
<template>
<div :class="{'hidden':hidden}" class="pagination-container">
<el-pagination
:background="background"
:current-page.sync="currentPage"
:page-size.sync="pageSize"
:layout="layout"
:page-sizes="pageSizes"
:total="total"
v-bind="$attrs"
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
/>
</div>
</template>
<script>
// import { scrollTo } from '@/utils/scroll-to'
export default {
name: 'Pagination',
props: {
total: {
required: true,
type: Number
},
page: {
type: Number,
default: 1
},
limit: {
type: Number,
default: 10
},
pageSizes: {
type: Array,
default() {
return [10, 20, 30, 50]
}
},
layout: {
type: String,
default: 'total, sizes, prev, pager, next, jumper'
},
background: {
type: Boolean,
default: true
},
autoScroll: {
type: Boolean,
default: true
},
hidden: {
type: Boolean,
default: false
}
},
computed: {
currentPage: {
get() {
return this.page
},
set(val) {
this.$emit('update:page', val)
}
},
pageSize: {
get() {
return this.limit
},
set(val) {
this.$emit('update:limit', val)
}
}
},
methods: {
handleSizeChange(val) {
this.$emit('pagination', { page: this.currentPage, limit: val })
// if (this.autoScroll) {
// scrollTo(0, 800)
// }
},
handleCurrentChange(val) {
this.$emit('pagination', { page: val, limit: this.pageSize })
// if (this.autoScroll) {
// scrollTo(0, 800)
// }
}
}
}
</script>
<style scoped>
.pagination-container {
background: #fff;
padding: 32px 16px;
}
.pagination-container.hidden {
display: none;
}
</style>
2) Usado en el componente principal, simplificado un poco, el código es el siguiente
<paginationCom :total="total" @getTableData="getTableData"></paginationCom>
import paginationCom from "@/components/pagination.vue"; //分页组件
data() {
return { total: 0,},
components:{
paginationCom
},
//----------------- 查询列表--------------
getCourseChapterList(page = 1) { //专栏
this.loadingTable = true;
let obj = { page, pageSize: 10 }
console.log(obj, d.decryptByDES(d.encryptByDES(JSON.stringify(obj))))
getCourseChapterList(d.encryptByDES(JSON.stringify(obj))).then(res => {
if (res.code == 0) {
this.total=res.data.total
this.tableData = JSON.parse(d.decryptByDES(res.data.list))
this.loadingTable = false;
} else {
this.$message.error(res.msg);
}
console.log(this.tableData, '专栏list')
})
},
// ----------------换页------------------
getTableData(val) {
this.getCourseContentList(Number(val))
},
2.uview2 carga más
<view class=""><u-loadmore :status="status" /></view>
data() {
return {
status: 'loadmore',
page: 1, //加载更多当前页数
n: 1, //当前列表的total
currentE: '' //点击的折叠面板的当前专栏的id,
list2:[] //列表数据
}
onReachBottom() {
console.log('onreachbotton到底了', this.n);
if (this.n > this.page) {
this.status = 'loading';
this.page++;
this.getCollList(this.page, this.currentE);
} else {
this.status = 'nomore';
}
},
getCollList(page, e) {
this.$http('接口地址', 'POST', {
page,
pageSize: 10,
chapter_id: e
}).then(res => {
if (res.code == 0) {
this.list2.push(...JSON.parse(this.$d.decryptByDES(res.data.list)));
if (res.data.total > 10) {
this.n =parseInt(res.data.total/10)+1
}
console.log(res,this.n, '接口数据2视频888888', this.list2);
}
});
},