<span id="mktg5"></span>

<i id="mktg5"><meter id="mktg5"></meter></i>

        <label id="mktg5"><meter id="mktg5"></meter></label>
        最新文章專題視頻專題問答1問答10問答100問答1000問答2000關鍵字專題1關鍵字專題50關鍵字專題500關鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關鍵字專題關鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
        問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
        當前位置: 首頁 - 科技 - 知識百科 - 正文

        Vue2.5 結合 Element UI 之 Table 和 Pagination 組件實現分頁功能

        來源:懂視網 責編:小采 時間:2020-11-27 22:20:45
        文檔

        Vue2.5 結合 Element UI 之 Table 和 Pagination 組件實現分頁功能

        Vue2.5 結合 Element UI 之 Table 和 Pagination 組件實現分頁功能:2017年底了,總結了這一年多來的前端之路,Vue從入門到放棄,再二進宮,從 Vue1.0 持續跟蹤到 Vue2.5。結合公司的一些實際項目,也封裝了一些比較實用的組件。 由于現在公司管理平臺主要運用Element UI,索性就結合組件Table 和 Pagination
        推薦度:
        導讀Vue2.5 結合 Element UI 之 Table 和 Pagination 組件實現分頁功能:2017年底了,總結了這一年多來的前端之路,Vue從入門到放棄,再二進宮,從 Vue1.0 持續跟蹤到 Vue2.5。結合公司的一些實際項目,也封裝了一些比較實用的組件。 由于現在公司管理平臺主要運用Element UI,索性就結合組件Table 和 Pagination

        2017年底了,總結了這一年多來的前端之路,Vue從入門到放棄,再二進宮,從 Vue1.0 持續跟蹤到 Vue2.5。結合公司的一些實際項目,也封裝了一些比較實用的組件。

        由于現在公司管理平臺主要運用Element UI,索性就結合組件Table 和 Pagination 封裝了一個支持頁面切換的Table組件,不啰嗦,直接上代碼。

        2、實現思路

        2.1、Element UI 引入(整體引入)

        main.js

        // Element UI
        import Element from 'element-ui'
        // 默認樣式
        import 'element-ui/lib/theme-chalk/index.css'

        2.2、開始封裝 iTable.vue 組件 (骨架)

        由于公司項目都是以 i 開頭,所以,為了區分組件和頁面,習慣于組件命名也以 i 開頭。 首先把 Table 、 Pagination 組件加進來

        <template>
         <div class="table">
         <!--region 表格-->
         <el-table id="iTable"></el-table>
         <!--endregion-->
         <!--region 分頁-->
         <el-pagination></el-pagination>
         <!--endregion-->
         </div>
        <template>

        養成寫注釋的好習慣,個人項目的注釋量基本上不會低于 30%

        2.3、在頁面中引用 iTable 組件,并且給 iTable 組件傳值

        <template>
         <div class="table-page">
         <i-table :list="list" 
         :total="total" 
         :otherHeight="otherHeight"
         @handleSizeChange="handleSizeChange"
         @handleIndexChange="handleIndexChange" @handleSelectionChange="handleSelectionChange"
         :options="options"
         :columns="columns"
         :operates="operates"
         @handleFilter="handleFilter"
         @handelAction="handelAction">
         </i-table>
         </div>
        </template>
        <script>
         import iTable from '../../components/Table/Index'
         export default {
         components: {iTable},
         data () {
         return {
         total: 0, // table數據總條數
         list: [], // table數據
         otherHeight: 208, // 除了table表格之外的高度,為了做table表格的高度自適應
         page: 1, // 當前頁碼
         limit: 20, // 每頁數量
         options: {
         stripe: true, // 是否為斑馬紋 table
         loading: false, // 是否添加表格loading加載動畫
         highlightCurrentRow: true, // 是否支持當前行高亮顯示
         mutiSelect: true, // 是否支持列表項選中功能
         filter: false, // 是否支持數據過濾功能
         action: false // 是否支持 表格操作功能
         }, // table 的參數
         columns: [
         {
         prop: 'id',
         label: '編號',
         align: 'center',
         width: 60
         },
         {
         prop: 'title',
         label: '標題',
         align: 'center',
         width: 400,
         formatter: (row, column, cellValue) => {
         return `<span style="white-space: nowrap;color: dodgerblue;">${row.title}</span>`
         }
         },
         {
         prop: 'state',
         label: '狀態',
         align: 'center',
         width: '160',
         render: (h, params) => {
         return h('el-tag', {
         props: {type: params.row.state === 0 ? 'success' : params.row.state === 1 ? 'info' : 'danger'} // 組件的props
         }, params.row.state === 0 ? '上架' : params.row.state === 1 ? '下架' : '審核中')
         }
         },
         ……
         ], // 需要展示的列
         operates: {
         width: 200,
         fixed: 'right',
         list: [
         {
         label: '編輯',
         type: 'warning',
         show: true,
         icon: 'el-icon-edit',
         plain: true,
         disabled: true,
         method: (index, row) => {
         this.handleEdit(index, row)
         }
         },
         {
         label: '刪除',
         type: 'danger',
         icon: 'el-icon-delete',
         show: true,
         plain: false,
         disabled: false,
         method: (index, row) => {
         this.handleDel(index, row)
         }
         }
         ]
         } // 列操作按鈕
         }
         },
         methods: {
         // 切換每頁顯示的數量
         handleSizeChange (size) {
         this.limit = size
         console.log(' this.limit:', this.limit)
         },
         // 切換頁碼
         handleIndexChange (index) {
         this.page = index
         console.log(' this.page:', this.page)
         },
         // 選中行
         handleSelectionChange (val) {
         console.log('val:', val)
         },
         // 編輯
         handleEdit (index, row) {
         console.log(' index:', index)
         console.log(' row:', row)
         },
         // 刪除
         handleDel (index, row) {
         console.log(' index:', index)
         console.log(' row:', row)
         }
         }
         }
        </script>

        除了 columns 參數和 operates 參數 之外,其它的參數應該還好理解,好的。那我們就詳細的解釋下這兩個參數,那么我們就需要結合組件iTable.vue 來講解了,接下來就給 iTable.vue 添加肌肉和血管,代碼都貼了。 比較難理解的就是columns里面的 render 參數,使用了Vue的虛擬標簽,為了就是能夠在 table 表格的列中隨心所欲的使用各種html標簽 和 element UI 的其他組件。( 你也可以直接寫,看看 table 組件是否能識別,呵呵噠! )這個估計對于剛入門的小伙伴是一個比較難理解的地方,詳細的大家可以先看下vue 的render,解釋的更清楚,如果有的小伙伴不理解,可以直接私信我~~~

        <!--region 封裝的分頁 table-->
        <template>
         <div class="table">
         <el-table id="iTable" v-loading.iTable="options.loading" :data="list" :max-height="height" :stripe="options.stripe"
         ref="mutipleTable"
         @selection-change="handleSelectionChange">
         <!--region 選擇框-->
         <el-table-column v-if="options.mutiSelect" type="selection" style="width: 55px;">
         </el-table-column>
         <!--endregion-->
         <!--region 數據列-->
         <template v-for="(column, index) in columns">
         <el-table-column :prop="column.prop"
         :label="column.label"
         :align="column.align"
         :width="column.width">
         <template slot-scope="scope">
         <template v-if="!column.render">
         <template v-if="column.formatter">
         <span v-html="column.formatter(scope.row, column)"></span>
         </template>
         <template v-else>
         <span>{{scope.row[column.prop]}}</span>
         </template>
         </template>
         <template v-else>
         <expand-dom :column="column" :row="scope.row" :render="column.render" :index="index"></expand-dom>
         </template>
         </template>
         </el-table-column>
         </template>
         <!--endregion-->
         <!--region 按鈕操作組-->
         <el-table-column ref="fixedColumn" label="操作" align="center" :width="operates.width" :fixed="operates.fixed"
         v-if="operates.list.filter(_x=>_x.show === true).length > 0">
         <template slot-scope="scope">
         <div class="operate-group">
         <template v-for="(btn, key) in operates.list">
         <div class="item" v-if="btn.show">
         <el-button :type="btn.type" size="mini" :icon="btn.icon" :disabled="btn.disabled"
         :plain="btn.plain" @click.native.prevent="btn.method(key,scope.row)">{{ btn.label }}
         </el-button>
         </div>
         </template>
         </div>
         </template>
         </el-table-column>
         <!--endregion-->
         </el-table>
         <div style="height:12px"></div>
         <!--region 分頁-->
         <el-pagination @size-change="handleSizeChange"
         @current-change="handleIndexChange"
         :page-size="pageSize"
         :page-sizes="[10, 20, 50]" :current-page="pageIndex" layout="total,sizes, prev, pager, next,jumper"
         :total="total"></el-pagination>
         <!--endregion-->
         <!--region 數據篩選-->
         <div class="filter-data fix-right" v-show="options.filter" @click="showfilterDataDialog">
         <span>篩選過濾</span>
         </div>
         <!--endregion-->
         <!--region 表格操作-->
         <div class="table-action fix-right" v-show="options.action" @click="showActionTableDialog">
         <span>表格操作</span>
         </div>
         <!--endregion-->
         </div>
        </template>
        <!--endregion-->
        <script>
         export default {
         props: {
         list: {
         type: Array,
         default: []
         }, // 數據列表
         columns: {
         type: Array,
         default: []
         }, // 需要展示的列 === prop:列數據對應的屬性,label:列名,align:對齊方式,width:列寬
         operates: {
         type: Array,
         default: []
         }, // 操作按鈕組 === label: 文本,type :類型(primary / success / warning / danger / info / text),show:是否顯示,icon:按鈕圖標,plain:是否樸素按鈕,disabled:是否禁用,method:回調方法
         total: {
         type: Number,
         default: 0
         }, // 總數
         pageSize: {
         type: Number,
         default: 20
         }, // 每頁顯示的數量
         otherHeight: {
         type: Number,
         default: 160
         }, // 用來計算表格的高度
         options: {
         type: Object,
         default: {
         stripe: false, // 是否為斑馬紋 table
         highlightCurrentRow: false // 是否要高亮當前行
         },
         filter: false,
         action: false
         } // table 表格的控制參數
         },
         components: {
         expandDom: {
         functional: true,
         props: {
         row: Object,
         render: Function,
         index: Number,
         column: {
         type: Object,
         default: null
         }
         },
         render: (h, ctx) => {
         const params = {
         row: ctx.props.row,
         index: ctx.props.index
         }
         if (ctx.props.column) params.column = ctx.props.column
         return ctx.props.render(h, params)
         }
         }
         },
         data () {
         return {
         pageIndex: 1,
         multipleSelection: [] // 多行選中
         }
         },
         mounted () {
         },
         computed: {
         height () {
         return this.$utils.Common.getWidthHeight().height - this.otherHeight
         }
         },
         methods: {
         // 切換每頁顯示的數量
         handleSizeChange (size) {
         this.$emit('handleSizeChange', size)
         this.pageIndex = 1
         },
         // 切換頁碼
         handleIndexChange (index) {
         this.$emit('handleIndexChange', index)
         this.pageIndex = index
         },
         // 多行選中
         handleSelectionChange (val) {
         this.multipleSelection = val
         this.$emit('handleSelectionChange', val)
         },
         // 顯示 篩選彈窗
         showfilterDataDialog () {
         this.$emit('handleFilter')
         },
         // 顯示 表格操作彈窗
         showActionTableDialog () {
         this.$emit('handelAction')
         }
         }
         }
        </script>
        <style lang="less" rel="stylesheet/less">
         @import "../../assets/styles/mixins";
         .table {
         height: 100%;
         .el-pagination {
         float: right;
         margin: 20px;
         }
         .el-table__header-wrapper, .el-table__fixed-header-wrapper {
         thead {
         tr {
         th {
         color: #333333;
         }
         }
         }
         }
         .el-table-column--selection .cell {
         padding: 0;
         text-align: center;
         }
         .el-table__fixed-right {
         bottom: 0 !important;
         right: 6px !important;
         z-index: 1004;
         }
         .operate-group {
         display: flex;
         flex-wrap: wrap;
         .item {
         margin-top: 4px;
         margin-bottom: 4px;
         display: block;
         flex: 0 0 50%;
         }
         }
         .filter-data {
         top: e("calc((100% - 100px) / 3)");
         background-color: rgba(0, 0, 0, 0.7);
         }
         .table-action {
         top: e("calc((100% - 100px) / 2)");
         background-color: rgba(0, 0, 0, 0.7);
         }
         .fix-right {
         position: absolute;
         right: 0;
         height: 100px;
         color: #ffffff;
         width: 30px;
         display: block;
         z-index: 1005;
         writing-mode: vertical-rl;
         text-align: center;
         line-height: 28px;
         border-bottom-left-radius: 6px;
         border-top-left-radius: 6px;
         cursor: pointer;
         }
         }
        </style>

        總結

        以上所述是小編給大家介紹的Vue2.5 結合 Element UI 之 Table 和 Pagination 組件實現分頁功能,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網站的支持!

        聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

        文檔

        Vue2.5 結合 Element UI 之 Table 和 Pagination 組件實現分頁功能

        Vue2.5 結合 Element UI 之 Table 和 Pagination 組件實現分頁功能:2017年底了,總結了這一年多來的前端之路,Vue從入門到放棄,再二進宮,從 Vue1.0 持續跟蹤到 Vue2.5。結合公司的一些實際項目,也封裝了一些比較實用的組件。 由于現在公司管理平臺主要運用Element UI,索性就結合組件Table 和 Pagination
        推薦度:
        標簽: VUE 組件 分頁
        • 熱門焦點

        最新推薦

        猜你喜歡

        熱門推薦

        專題
        Top
        主站蜘蛛池模板: 狠狠亚洲狠狠欧洲2019| 巨胸喷奶水视频www网免费| 国产精品亚洲mnbav网站| 日日摸夜夜添夜夜免费视频| 国产三级电影免费观看| 国产亚洲一卡2卡3卡4卡新区 | 99亚洲乱人伦aⅴ精品| 永久在线毛片免费观看| 美女黄频视频大全免费的| 可以免费观看的一级毛片| 一级一黄在线观看视频免费| 亚洲中文字幕无码日韩| 国产一级淫片a免费播放口| 亚洲精品91在线| 国产成人免费网站| 亚洲av永久中文无码精品| 亚洲精品偷拍视频免费观看 | 国产亚洲欧美日韩亚洲中文色| 日本免费v片一二三区| 免费一级全黄少妇性色生活片| 亚洲人成77777在线播放网站| 日韩电影免费在线观看网站| 亚洲色欲www综合网| 国产A在亚洲线播放| 中文字幕久精品免费视频| 蜜芽亚洲av无码一区二区三区| 国产精品无码免费专区午夜| 国产亚洲精aa成人网站| 无码精品人妻一区二区三区免费| 国产成A人亚洲精V品无码性色| 在线观看免费av网站| 亚洲精品第一综合99久久| 最新中文字幕免费视频| 色网站在线免费观看| 国产亚洲综合网曝门系列| 黄色网址免费观看| 美女羞羞视频免费网站| 久久亚洲美女精品国产精品 | 精品一区二区三区免费毛片| 国外亚洲成AV人片在线观看| 国产免费的野战视频|