下一页 .page-wrap {display: flex;align-items: center;justify-content: flex-end;text-align: right;user-select: none;.li-page {curs。Nuxt.js-手写一个分页组件。" />

Nuxt.js-手写一个分页组件

1、HTML && CSS

@/components/Paginationn.vue
.page-wrap { display: flex; align-items: center; justify-content: flex-end; text-align: right; user-select: none; .li-page { cursor: pointer; width: 65px; height: 32px; line-height: 32px; border: 1px solid rgba(204, 204, 204, 1); border-radius: 2px; text-align: center; margin-left: 12px; } .li-page:hover { color: #fff; background: rgba(67, 137, 255, 1); } ul { li { position: relative; float: left; width: 40px; height: 32px; line-height: 32px; font-size: 14px; border: 1px solid rgba(204, 204, 204, 1); border-radius: 2px; text-align: center; margin-left: 12px; cursor: pointer; div { position: absolute; width: 100%; height: 100%; z-index: 2; } a:hover { color: #fff; } } li:hover, li.active { color: #fff; background: rgba(67, 137, 255, 1); a { color: #fff; } } } }

2、Store
@/store/pagination.js
export const state = () => ({ offset: 0, })export const mutations = { // 上一页 PRE_PAGE(state, offset) { state.offset -= offset }, // 下一页 NEXT_PAGE(state, offset) { state.offset += offset }, GO_PAGE(state, offset) { state.offset = offset }, }

3、使用
import Pagination from '@/components/Pagination'export default { components: { Pagination, }, methods:{ async getByPage(page) { // 获取第 page 页数据 } } }

4、效果 Nuxt.js-手写一个分页组件
文章图片

    推荐阅读