Commit dcf3a32d authored by June's avatar June

分页

parent 34aac71b
import { isFunction } from '@/utils/types.js'
import Toast from '@/lib/storage/index.js'
/**
* 多页加载
*/
class ListPages {
constructor() {
this.page = 1 // 当前页面
this.counts = 10 // 每页的数量
this.flat = false // 是否在请求
}
async getList(cb) {
try {
if(this.flat || !isFunction(cb)) return console.log('正在请求中获取callback不是函数')
await cb.call(this, this.page, this.counts)
this.page ++
this.flat = false
} catch (error) {
console.log(error)
Toast({title: '获取列表失败'})
}
}
// 将页数重置为0 不重置为0也可以 看情况处理
async refresh(cb) {
try {
if(this.flat || !isFunction(cb)) return console.log('正在请求中获取callback不是函数')
this.page = 1
await cb.call(this, 1, this.counts)
this.page ++
this.flat = false
} catch (error) {
console.log(error)
Toast({title: '获取列表失败'})
}
}
}
export default ListPages
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment