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

Vue分頁(yè)組件的封裝方法

 更新時(shí)間:2022年07月05日 16:44:28   作者:kanami154  
這篇文章主要為大家詳細(xì)介紹了Vue分頁(yè)組件的封裝方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

前言

這個(gè)是基于vue2的分頁(yè)封裝,仿照elementUI而寫(xiě)的組件。

效果如圖

話不多說(shuō),直接上代碼

<template>
? <div class="pagination">
? ? <!-- 總頁(yè)數(shù) -->
? ? <div class="total">共{{ total }}條</div>
? ? <!-- 選擇每頁(yè)的條數(shù) -->
? ? <select name="" id="size_select" v-model="sizes" @change="sizeChange">
? ? ? <option v-for="item in pageSizes" :key="item" :value="item">
? ? ? ? {{ item }}條/頁(yè)
? ? ? </option>
? ? </select>
? ? <div class="pagenum">
? ? ? <!-- 上一頁(yè) -->
? ? ? <el-button
? ? ? ? icon="el-icon-arrow-left"
? ? ? ? :disabled="backDisabled"
? ? ? ? circle
? ? ? ? @click="back"
? ? ? ></el-button>
? ? ? <!-- 頁(yè)碼 -->
? ? ? <ul>
? ? ? ? <li
? ? ? ? ? :class="currentPage == item ? 'active' : ''"
? ? ? ? ? v-for="(item, index) in pagenum"
? ? ? ? ? :key="index"
? ? ? ? ? @click="toPage(item)"
? ? ? ? >
? ? ? ? ? {{ item }}
? ? ? ? </li>
? ? ? </ul>
? ? ? <!-- 下一頁(yè) -->
? ? ? <el-button
? ? ? ? icon="el-icon-arrow-right"
? ? ? ? :disabled="forwardDisabled"
? ? ? ? circle
? ? ? ? @click="forward"
? ? ? ></el-button>
? ? </div>
? </div>
</template>
?
<script>
export default {
? name: "pagination",
? props: {
? ? total: { ?// 總數(shù)
? ? ? type: null,
? ? ? required: true,
? ? },
? ? pageSizes: { // 可選擇的每頁(yè)條數(shù)
? ? ? type: Array,
? ? },
? ? pageSize: { ?// 每頁(yè)顯示的條數(shù)
? ? ? type: Number,
? ? ? required: true,
? ? },
? ? currentPage: { // 當(dāng)前頁(yè)
? ? ? type: Number,
? ? ? required: true,
? ? },
? },
? data() {
? ? return {
? ? ? sizes: this.pageSize, ?// 接收props傳來(lái)的pageSize
? ? ? nowPage: this.currentPage, ?// 接收props傳來(lái)的currentPage
? ? };
? },
? computed: {
? ? allPage() { ?// 計(jì)算所有的頁(yè)數(shù)
? ? ? return Math.ceil(this.total / this.pageSize);
? ? },
? ? backDisabled() { ?// 是否禁用上一頁(yè)
? ? ? return this.currentPage == 1;
? ? },
? ? forwardDisabled() { // 是否禁用下一頁(yè)
? ? ? return this.currentPage == this.allPage;
? ? },
? ? pagenum() { ? // 計(jì)算顯示不同的頁(yè)
? ? ? if (this.allPage - this.nowPage > 6) { ?// ?
? ? ? ? if (this.nowPage > 6) {
? ? ? ? ? return [
? ? ? ? ? ? 1,
? ? ? ? ? ? "...",
? ? ? ? ? ? this.nowPage - 2,
? ? ? ? ? ? this.nowPage - 1,
? ? ? ? ? ? this.nowPage,
? ? ? ? ? ? this.nowPage + 1,
? ? ? ? ? ? this.nowPage + 2,
? ? ? ? ? ? "...",
? ? ? ? ? ? this.allPage,
? ? ? ? ? ];
? ? ? ? } else {
? ? ? ? ? if (this.allPage > 8) {
? ? ? ? ? ? return [1, 2, 3, 4, 5, 6, "...", this.allPage];
? ? ? ? ? } else {
? ? ? ? ? ? return this.allPage;
? ? ? ? ? }
? ? ? ? }
? ? ? } else {
? ? ? ? if (this.nowPage < 6) {
? ? ? ? ? return this.allPage;
? ? ? ? } else {
? ? ? ? ? return [
? ? ? ? ? ? 1,
? ? ? ? ? ? "...",
? ? ? ? ? ? this.allPage - 5,
? ? ? ? ? ? this.allPage - 4,
? ? ? ? ? ? this.allPage - 3,
? ? ? ? ? ? this.allPage - 2,
? ? ? ? ? ? this.allPage - 1,
? ? ? ? ? ? this.allPage,
? ? ? ? ? ];
? ? ? ? }
? ? ? }
? ? },
? },
? methods: {
? ? sizeChange() { ?// 每頁(yè)限制條數(shù)改變觸發(fā)事件
? ? ? this.$emit("sizeChange", this.sizes);
? ? },
? ? forward() { ?// 點(diǎn)擊下一頁(yè)
? ? ? this.$emit("currentChange", (this.nowPage += 1));
? ? },
? ? back() { ?// 點(diǎn)擊上一頁(yè)
? ? ? this.$emit("currentChange", (this.nowPage -= 1));
? ? },
? ? toPage(val) { ?// 點(diǎn)擊頁(yè)數(shù)
? ? ? if (val == "...") {
? ? ? ? console.log(2);
? ? ? } else {
? ? ? ? this.nowPage = val;
? ? ? ? this.$emit("currentChange", val);
? ? ? }
? ? },
? },
};
</script>

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

相關(guān)文章

最新評(píng)論

洛宁县| 波密县| 麻城市| 桑植县| 遂宁市| 青州市| 常宁市| 大新县| 太康县| 尚志市| 阆中市| 延吉市| 西贡区| 南川市| 汪清县| 迁西县| 遵化市| 镇雄县| 石屏县| 和田市| 马公市| 上犹县| 乐山市| 萨嘎县| 昆山市| 建宁县| 镇康县| 安远县| 镇雄县| 山阳县| 图木舒克市| 香港 | 永靖县| 石门县| 同心县| 林西县| 亳州市| 长沙县| 桂阳县| 苏尼特右旗| 兴城市|