最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Vue分頁器組件使用方法詳解

 更新時間:2022年03月03日 17:59:44   作者:theMuseCatcher  
這篇文章主要為大家詳細介紹了Vue分頁器組件的使用方法,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了Vue分頁器組件的使用,供大家參考,具體內(nèi)容如下

效果圖如下:

鼠標(biāo)懸浮時切換為箭頭:

①創(chuàng)建自定義分頁組件Pager.vue:預(yù)設(shè)主題色為@themeColor: #D93844; 每頁展示10條數(shù)據(jù),一次最多顯示5個頁碼,支持輸入頁碼跳轉(zhuǎn):

<template>
? <div class="m-pager-wrap" v-if="totalCount">
? ? <span class="u-text">共{{ totalPage }}頁 / {{ totalCount }}條</span>
? ? <span class="u-item txt" :class="{'disabled': currentPage===1}" @click="changePage(1)">首頁</span>
? ? <span class="u-item txt" :class="{'disabled': currentPage===1}" @click="changePage(currentPage - 1)">上一頁</span>
? ? <span
? ? ? class="u-ellipsis"
? ? ? ref="forward"
? ? ? v-show="forwardMore"
? ? ? @click="onForward"
? ? ? @mouseenter="onEnterForward"
? ? ? @mouseleave="onLeaveForward">&middot;&middot;&middot;</span>
? ? <span :class="['u-item', {'active': currentPage===num}]" v-for="num in pageList" :key="num" @click="changePage(num)">{{ num }}</span>
? ? <span
? ? ? class="u-ellipsis"
? ? ? ref="backward"
? ? ? v-show="backwardMore"
? ? ? @click="onBackward"
? ? ? @mouseenter="onEnterBackward"
? ? ? @mouseleave="onLeaveBackward">&middot;&middot;&middot;</span>
? ? <span class="u-item txt" :class="{'disabled': currentPage===totalPage}" @click="changePage(currentPage + 1)">下一頁</span>
? ? <span class="u-item txt" :class="{'disabled': currentPage===totalPage}" @click="changePage(totalPage)">尾頁</span>
? ? <span class="u-jump-page">跳至<input type="text" v-model="jumpNumber"/>頁</span>
? ? <span class="u-item txt" @click="jumpPage(jumpNumber)">確定</span>
? </div>
</template>
<script>
export default {
? name: 'Pager',
? data () {
? ? return {
? ? ? currentPage: this.pageNumber, // 當(dāng)前頁碼
? ? ? currentSize: this.pageSize, // 分頁數(shù)
? ? ? jumpNumber: '', // 跳轉(zhuǎn)的頁碼
? ? ? forwardMore: false, // 左箭頭展示
? ? ? backwardMore: false // 右箭頭展示
? ? }
? },
? props: {
? ? pageNumber: { // 當(dāng)前頁面
? ? ? type: Number,
? ? ? default: 1
? ? },
? ? pageSize: { // 每頁顯示數(shù)量 [10條/頁 20條/頁 30條/頁 40條/頁]
? ? ? type: Number,
? ? ? default: 10
? ? },
? ? totalCount: { // 總條數(shù)
? ? ? type: Number,
? ? ? default: 0
? ? },
? ? pageListNum: { // 顯示的頁碼數(shù)組長度
? ? ? type: Number,
? ? ? default: 5
? ? }
? },
? computed: {
? ? totalPage () { // 總頁數(shù)
? ? ? return Math.ceil(this.totalCount / this.currentSize) // 向上取整
? ? },
? ? pageList () { // 獲取顯示的頁碼數(shù)組
? ? ? return this.dealPageList(this.currentPage)
? ? }
? },
? watch: {
? ? currentPage (to, from) {
? ? ? // 通過更改當(dāng)前頁碼,修改分頁數(shù)據(jù)
? ? ? this.$emit('changePage', { currentPage: to, currentSize: this.currentSize })
? ? }
? },
? created () {
? ? // 監(jiān)聽鍵盤Enter按鍵
? ? document.onkeydown = (e) => {
? ? ? const ev = e || window.event
? ? ? if (ev && ev.keyCode === 13 && this.jumpNumber) {
? ? ? ? this.jumpPage(this.jumpNumber)
? ? ? }
? ? }
? },
? methods: {
? ? dealPageList (curPage) {
? ? ? var resList = []
? ? ? var offset = Math.floor(this.pageListNum / 2) // 向下取整
? ? ? var pager = {
? ? ? ? start: curPage - offset,
? ? ? ? end: curPage + offset
? ? ? }
? ? ? if (pager.start < 1) {
? ? ? ? pager.end = pager.end + (1 - pager.start)
? ? ? ? pager.start = 1
? ? ? }
? ? ? if (pager.end > this.totalPage) {
? ? ? ? pager.start = pager.start - (pager.end - this.totalPage)
? ? ? ? pager.end = this.totalPage
? ? ? }
? ? ? if (pager.start < 1) {
? ? ? ? pager.start = 1
? ? ? }
? ? ? if (pager.start > 1) {
? ? ? ? this.forwardMore = true
? ? ? } else {
? ? ? ? this.forwardMore = false
? ? ? }
? ? ? if (pager.end < this.totalPage) {
? ? ? ? this.backwardMore = true
? ? ? } else {
? ? ? ? this.backwardMore = false
? ? ? }
? ? ? // 生成要顯示的頁碼數(shù)組
? ? ? for (let i = pager.start; i <= pager.end; i++) {
? ? ? ? resList.push(i)
? ? ? }
? ? ? return resList
? ? },
? ? onEnterForward () {
? ? ? this.$refs.forward.innerHTML = '&laquo;'
? ? },
? ? onLeaveForward () {
? ? ? this.$refs.forward.innerHTML = '&middot;&middot;&middot;'
? ? },
? ? onEnterBackward () {
? ? ? this.$refs.backward.innerHTML = '&raquo;'
? ? },
? ? onLeaveBackward () {
? ? ? this.$refs.backward.innerHTML = '&middot;&middot;&middot;'
? ? },
? ? onForward () {
? ? ? this.currentPage = this.currentPage - this.pageListNum > 0 ? this.currentPage - this.pageListNum : 1
? ? },
? ? onBackward () {
? ? ? this.currentPage = this.currentPage + this.pageListNum < this.totalPage ? this.currentPage + this.pageListNum : this.totalPage
? ? },
? ? jumpPage (jumpNum) {
? ? ? if (Number(jumpNum)) {
? ? ? ? if (Number(jumpNum) < 1) {
? ? ? ? ? jumpNum = 1
? ? ? ? }
? ? ? ? if (Number(jumpNum) > this.totalPage) {
? ? ? ? ? jumpNum = this.totalPage
? ? ? ? }
? ? ? ? this.changePage(Number(jumpNum))
? ? ? }
? ? ? this.jumpNumber = '' // 清空跳轉(zhuǎn)輸入框
? ? },
? ? changePage (pageNum) {
? ? ? if (this.currentPage !== pageNum) { // 點擊的頁碼不是當(dāng)前頁碼
? ? ? ? this.currentPage = pageNum
? ? ? }
? ? }
? }
}
</script>
<style lang="less" scoped>
@themeColor: #D93844; // 自定義主題色
.m-pager-wrap {
? height: 32px;
? line-height: 30px;
? font-size: 14px;
? color: #888;
? text-align: center;
? .u-text {
? ? margin-right: 5px;
? }
? .u-item {
? ? margin-right: 5px;
? ? min-width: 30px;
? ? display: inline-block;
? ? user-select: none; // 禁止選取文本
? ? border: 1px solid #d9d9d9;
? ? border-radius: 4px;
? ? cursor: pointer;
? ? &:hover {
? ? ? .active();
? ? }
? }
? .active {
? ? color: #fff;
? ? background: @themeColor;
? ? border: 1px solid @themeColor;
? }
? .disabled {
? ? color: rgba(0,0,0,.25);
? ? &:hover {
? ? ? cursor: not-allowed;
? ? ? color: rgba(0,0,0,.25);
? ? ? background: #fff;
? ? ? border: 1px solid #d9d9d9;
? ? }
? }
? .txt {
? ? padding: 0 6px;
? }
? .u-ellipsis {
? ? display: inline-block;
? ? width: 12px;
? ? padding: 0 8px;
? ? margin-right: 5px;
? ? cursor: pointer;
? ? &:hover {
? ? ? color: @themeColor;
? ? }
? }
? .u-jump-page {
? ? margin: 0 8px 0 3px;
? ? input {
? ? ? width: 32px;
? ? ? height: 20px;
? ? ? padding: 5px 8px;
? ? ? margin: 0 5px;
? ? ? border: 1px solid #d9d9d9;
? ? ? border-radius: 4px;
? ? ? text-align: center;
? ? }
? }
}
</style>

②在要使用的頁面引入分頁器:

<div class="m-page">
?? ?<Pager
?? ??? ?@changePage="jumpPage"
?? ??? ?:totalCount="totalCount"
?? ??? ?:pageNumber="queryParams.p"
?? ??? ?:pageSize="queryParams.pageSize" />
</div>
?
import Pager from '@/components/Pager'
components: {
?? ?Pager
}
totalCount: 0,
queryParams: {
? ? ? ? pageSize: 10,
? ? ? ? p: 1,
? ? ? ? mod: 'search'
},
?
jumpPage (e) {
? ? ? this.queryParams.p = e.currentPage
? ? ? this.queryParams.pageSize = e.currentSize
? ? ? this.getDataLists() // 調(diào)用接口獲取列表數(shù)據(jù)
}
?
.m-page {
? margin: 30px auto 60px;
}

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • vue框架render方法如何替換template

    vue框架render方法如何替換template

    這篇文章主要介紹了vue框架render方法如何替換template,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-04-04
  • 在antd4.0中Form使用initialValue操作

    在antd4.0中Form使用initialValue操作

    這篇文章主要介紹了在antd4.0中Form使用initialValue操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-11-11
  • vue-video-player視頻播放器使用配置詳解

    vue-video-player視頻播放器使用配置詳解

    這篇文章主要為大家詳細介紹了vue-video-player視頻播放器的使用和配置,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-10-10
  • Vue3中使用mock.js模擬數(shù)據(jù)的示例詳解

    Vue3中使用mock.js模擬數(shù)據(jù)的示例詳解

    前后端同時開發(fā)的時候,后端接口數(shù)據(jù)沒有出來,前端可以使用mock模擬假數(shù)據(jù),所以下面小編就來為大家詳細介紹一下如何在Vue3中使用mock.js模擬數(shù)據(jù)吧
    2025-03-03
  • vue3前端實現(xiàn)全屏顯示及元素垂直填滿頁面效果

    vue3前端實現(xiàn)全屏顯示及元素垂直填滿頁面效果

    這篇文章主要給大家介紹了關(guān)于vue3前端實現(xiàn)全屏顯示及元素垂直填滿頁面效果的相關(guān)資料,文中還給大家介紹了vue3實現(xiàn)某一個元素全屏之后就黑屏了的解決辦法,需要的朋友可以參考下
    2024-02-02
  • vue2更改data里的變量不生效時,深層更改data里的變量問題

    vue2更改data里的變量不生效時,深層更改data里的變量問題

    這篇文章主要介紹了vue2更改data里的變量不生效時,深層更改data里的變量問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-03-03
  • vue.js實現(xiàn)請求數(shù)據(jù)的方法示例

    vue.js實現(xiàn)請求數(shù)據(jù)的方法示例

    這篇文章主要給大家介紹了vue.js實現(xiàn)請求數(shù)據(jù)的方法示例,文中分別介紹了vue1.0和vue2.0的示例方法,需要的朋友可以參考借鑒,下面來一起看看吧。
    2017-02-02
  • Vue實現(xiàn)virtual-dom的原理簡析

    Vue實現(xiàn)virtual-dom的原理簡析

    這篇文章主要介紹了Vue實現(xiàn)virtual-dom的原理簡析,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-07-07
  • Vue.js添加組件操作示例

    Vue.js添加組件操作示例

    這篇文章主要介紹了Vue.js添加組件操作,結(jié)合實例形式分析了vue.js組件的注冊、調(diào)用相關(guān)操作技巧,需要的朋友可以參考下
    2018-06-06
  • vue中的路由跳轉(zhuǎn)tabBar圖片和文字的高亮效果

    vue中的路由跳轉(zhuǎn)tabBar圖片和文字的高亮效果

    這篇文章主要介紹了vue中的路由跳轉(zhuǎn)tabBar圖片和文字的高亮效果,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-10-10

最新評論

黑山县| 陇川县| 沅江市| 拉萨市| 依安县| 涞源县| 万安县| 林甸县| 白城市| 杭锦旗| 花莲市| 黄陵县| 南平市| 信丰县| 土默特右旗| 临城县| 崇文区| 上思县| 太谷县| 彭州市| 扶余县| 开阳县| 太康县| 临潭县| 绥宁县| 平陆县| 简阳市| 台中市| 象山县| 信宜市| 定兴县| 阜平县| 永嘉县| 明水县| 图们市| 寿光市| 阿克| 鄂托克旗| 六安市| 筠连县| 灵寿县|