Implementation of component paging function in Vue2.5 and Element UI
This time I will bring you the components of Vue2.5 and Element UIPaging functionimplementation, what are the notesof implementing the component paging function of Vue2.5 and Element UI, The following is a practical case, let’s take a look.
It’s the end of 2017, and I summarized the front-end road for more than a year. Vue went from getting started to giving up, then entered the palace for the second time, and continued to track from Vue1.0 to Vue2.5. Combined with some actual projects of the company, some more practical components are also encapsulated.
Since the current company management platform mainly uses Element UI, we simply combined the components Table and Pagination to encapsulate a Table component that supports page switching. No verbosity, just enter the code directly.
2. Implementation ideas
2.1. Introduction of Element UI (overall introduction)
main .js
// Element UI import Element from 'element-ui' // 默认样式 import 'element-ui/lib/theme-chalk/index.css'
2.2. Start encapsulating the iTable.vue component (skeleton)
Since the company's projects all start with i, in order to distinguish components and pages, it is customary Component names also start with i. First, add the Table and Pagination components
<template> <p> <!--region 表格--> <el-table></el-table> <!--endregion--> <!--region 分页--> <el-pagination></el-pagination> <!--endregion--> </p> <template></template></template>
Develop a good habit of writing comments. The amount of comments for personal projects will basically not be less than 30%
2.3. In the page Reference the iTable component and pass the value to the iTable component
<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>
In addition to the columns parameter and the operators parameter, the other parameters should be easy to understand, okay. Then we will explain these two parameters in detail, then we need to combine the component iTable.vue to explain. Next, we will add muscles and blood vessels to iTable.vue, and the codes are posted. What is more difficult to understand is the render parameter in columns, which uses Vue's virtual tags in order to be able to use various html tags and other components of element UI in the columns of the table as desired. (You can also write it directly and see if the table component can be recognized, hahaha!) This is probably a difficult place to understand for those who are just getting started. For more details, you can first look at vue's render for a clearer explanation. , if some friends don’t understand, you can send me a private message directly~~~
<!--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>
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!
Recommended reading:
Summary of jQuery code optimization methods
Detailed explanation of asymmetric encryption of Node.js
CSS3 to achieve tilt and rotation animation effects
How to deal with incomplete page display in 360 browser compatibility mode
The above is the detailed content of Implementation of component paging function in Vue2.5 and Element UI. For more information, please follow other related articles on the PHP Chinese website!

JavaScriptisnotbuiltonCorC ;it'saninterpretedlanguagethatrunsonenginesoftenwritteninC .1)JavaScriptwasdesignedasalightweight,interpretedlanguageforwebbrowsers.2)EnginesevolvedfromsimpleinterpreterstoJITcompilers,typicallyinC ,improvingperformance.

JavaScript can be used for front-end and back-end development. The front-end enhances the user experience through DOM operations, and the back-end handles server tasks through Node.js. 1. Front-end example: Change the content of the web page text. 2. Backend example: Create a Node.js server.

Choosing Python or JavaScript should be based on career development, learning curve and ecosystem: 1) Career development: Python is suitable for data science and back-end development, while JavaScript is suitable for front-end and full-stack development. 2) Learning curve: Python syntax is concise and suitable for beginners; JavaScript syntax is flexible. 3) Ecosystem: Python has rich scientific computing libraries, and JavaScript has a powerful front-end framework.

The power of the JavaScript framework lies in simplifying development, improving user experience and application performance. When choosing a framework, consider: 1. Project size and complexity, 2. Team experience, 3. Ecosystem and community support.

Introduction I know you may find it strange, what exactly does JavaScript, C and browser have to do? They seem to be unrelated, but in fact, they play a very important role in modern web development. Today we will discuss the close connection between these three. Through this article, you will learn how JavaScript runs in the browser, the role of C in the browser engine, and how they work together to drive rendering and interaction of web pages. We all know the relationship between JavaScript and browser. JavaScript is the core language of front-end development. It runs directly in the browser, making web pages vivid and interesting. Have you ever wondered why JavaScr

Node.js excels at efficient I/O, largely thanks to streams. Streams process data incrementally, avoiding memory overload—ideal for large files, network tasks, and real-time applications. Combining streams with TypeScript's type safety creates a powe

The differences in performance and efficiency between Python and JavaScript are mainly reflected in: 1) As an interpreted language, Python runs slowly but has high development efficiency and is suitable for rapid prototype development; 2) JavaScript is limited to single thread in the browser, but multi-threading and asynchronous I/O can be used to improve performance in Node.js, and both have advantages in actual projects.

JavaScript originated in 1995 and was created by Brandon Ike, and realized the language into C. 1.C language provides high performance and system-level programming capabilities for JavaScript. 2. JavaScript's memory management and performance optimization rely on C language. 3. The cross-platform feature of C language helps JavaScript run efficiently on different operating systems.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Dreamweaver CS6
Visual web development tools
