這次帶給大家Vue2.5與Element UI的元件分頁功能實現,Vue2.5與Element UI的元件分頁功能實現的注意事項有哪些,下面就是實戰案例,一起來看一下。
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> <p> <!--region 表格--> <el-table></el-table> <!--endregion--> <!--region 分页--> <el-pagination></el-pagination> <!--endregion--> </p> <template></template></template>
養成寫註解的好習慣,個人項目的註解量基本上不會低於30%
2.3、在頁面中引用iTable 元件,並且給iTable 元件傳值
<template> <p> <i-table> </i-table> </p> </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}` } }, { 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> <p> <el-table> <!--region 选择框--> <el-table-column> </el-table-column> <!--endregion--> <!--region 数据列--> <template> <el-table-column> <template> <template> <template> <span></span> </template> <template> <span>{{scope.row[column.prop]}}</span> </template> </template> <template> <expand-dom></expand-dom> </template> </template> </el-table-column> </template> <!--endregion--> <!--region 按钮操作组--> <el-table-column>_x.show === true).length > 0"> <template> <p> <template> <p> <el-button>{{ btn.label }} </el-button> </p> </template> </p> </template> </el-table-column> <!--endregion--> </el-table> </p> <p></p> <!--region 分页--> <el-pagination></el-pagination> <!--endregion--> <!--region 数据筛选--> <p> <span>筛选过滤</span> </p> <!--endregion--> <!--region 表格操作--> <p> <span>表格操作</span> </p> <!--endregion--> </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> @import "../../assets/styles/mixins"; .table { height: 100%; .el-pagination { float: right; margin: 20px; } .el-tableheader-wrapper, .el-tablefixed-header-wrapper { thead { tr { th { color: #333333; } } } } .el-table-column--selection .cell { padding: 0; text-align: center; } .el-tablefixed-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>
相信看了本文案例你已經掌握了方法,更多精彩請關注php中文網其它相關文章!
推薦閱讀:
以上是Vue2.5與Element UI的元件分頁功能實現的詳細內容。更多資訊請關注PHP中文網其他相關文章!

Python和JavaScript的主要區別在於類型系統和應用場景。 1.Python使用動態類型,適合科學計算和數據分析。 2.JavaScript採用弱類型,廣泛用於前端和全棧開發。兩者在異步編程和性能優化上各有優勢,選擇時應根據項目需求決定。

選擇Python還是JavaScript取決於項目類型:1)數據科學和自動化任務選擇Python;2)前端和全棧開發選擇JavaScript。 Python因其在數據處理和自動化方面的強大庫而備受青睞,而JavaScript則因其在網頁交互和全棧開發中的優勢而不可或缺。

Python和JavaScript各有優勢,選擇取決於項目需求和個人偏好。 1.Python易學,語法簡潔,適用於數據科學和後端開發,但執行速度較慢。 2.JavaScript在前端開發中無處不在,異步編程能力強,Node.js使其適用於全棧開發,但語法可能複雜且易出錯。

javascriptisnotbuiltoncorc; sanInterpretedlanguagethatrunsonenginesoftenwritteninc.1)JavascriptwasdesignedAsignedAsalightWeight,drackendedlanguageforwebbrowsers.2)Enginesevolvedfromsimpleterterpretpretpretpretpreterterpretpretpretpretpretpretpretpretpretcompilerers,典型地,替代品。

JavaScript可用於前端和後端開發。前端通過DOM操作增強用戶體驗,後端通過Node.js處理服務器任務。 1.前端示例:改變網頁文本內容。 2.後端示例:創建Node.js服務器。

選擇Python還是JavaScript應基於職業發展、學習曲線和生態系統:1)職業發展:Python適合數據科學和後端開發,JavaScript適合前端和全棧開發。 2)學習曲線:Python語法簡潔,適合初學者;JavaScript語法靈活。 3)生態系統:Python有豐富的科學計算庫,JavaScript有強大的前端框架。

JavaScript框架的強大之處在於簡化開發、提升用戶體驗和應用性能。選擇框架時應考慮:1.項目規模和復雜度,2.團隊經驗,3.生態系統和社區支持。

引言我知道你可能會覺得奇怪,JavaScript、C 和瀏覽器之間到底有什麼關係?它們之間看似毫無關聯,但實際上,它們在現代網絡開發中扮演著非常重要的角色。今天我們就來深入探討一下這三者之間的緊密聯繫。通過這篇文章,你將了解到JavaScript如何在瀏覽器中運行,C 在瀏覽器引擎中的作用,以及它們如何共同推動網頁的渲染和交互。 JavaScript與瀏覽器的關係我們都知道,JavaScript是前端開發的核心語言,它直接在瀏覽器中運行,讓網頁變得生動有趣。你是否曾經想過,為什麼JavaScr


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

SublimeText3 Linux新版
SublimeText3 Linux最新版

ZendStudio 13.5.1 Mac
強大的PHP整合開發環境

EditPlus 中文破解版
體積小,語法高亮,不支援程式碼提示功能

SAP NetWeaver Server Adapter for Eclipse
將Eclipse與SAP NetWeaver應用伺服器整合。

MantisBT
Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。