只有数据和total时,前端做分页
const state: any = reactive({
pageParams: {
current: 1,
size: 10,
total: 0
},
searchParam: {},
dataSource: []
})
//动态计算页面数据
const paginatedData = computed(() => {
const startIndex = (state.pageParams.current - 1) * state.pageParams.size
const endIndex = startIndex + state.pageParams.size
//slice从dataSource中截取,从当前开始页的0-pageSize数据
return state.dataSource?.slice(startIndex, endIndex)
})
function getListFn() {
getUserByNameApi(state.searchParam).then((res: any) => {
if (res.code === 200) {
state.dataSource = res.data.records
state.pageParams.total = res.data.total
}
})
}
getListFn()