生活服务网站开发,做网站有哪些类型,手机网站怎么做,网站建好了seo怎么做如果后端没有分页api#xff0c;前端如何做分页一、使用computed
这个变量应该是计算之后的值#xff0c;是一个状态管理变量#xff0c;跟onMounted类似import {computed} from vue
// 定义ref储存rolelist#xff0c;这里是原始数据
const roleList ref([])// 定义页码…如果后端没有分页api前端如何做分页一、使用computed
这个变量应该是计算之后的值是一个状态管理变量跟onMounted类似import {computed} from vue
// 定义ref储存rolelist这里是原始数据
const roleList ref([])// 定义页码
let pageIndex ref(1)
// 定义显示的列表
let showRoles computed(() {// 切片操作return roles.value.slice((pageIndex.value-1) * 10, pageIndex)
})// 查询数据操作自己写将showRoles替换绑定表格数据,我这里是组件是父传子定义的一个变量tableData如果你这里插入的是一个表格那么应该是:DatashowRolesPublicTables :tableDatashowRoles multipleSelectionhandleSelection!-- template #selection /template --template #tableColumnel-table-column propertyroleId label角色ID /el-table-column propertyroleName label角色名 //templatetemplate #operationel-table-column label操作template #defaultscopeel-button sizesmall clickhandleEdit(scope.row)编辑/el-buttonel-button sizesmall typedanger clickhandleDelete(scope.row)删除/el-button/template/el-table-column/template/PublicTables二、添加分页器
template中添加分页器el-pagination sizesmall background layout prev, pager, next, total :totalroleList.length :current-pagepageIndex /这里current-page绑定绑定的页码会保持同步分页器总页数就是roleList的长度。
到这里应该已经实现了前端分页功能