Vue.js Element UI 合并列和分页组件完整代码示例 - 实现表格数据展示和分页功能
<p>"<template>\n <div>\n <el-table\n :data="tableData"\n border\n style="width: 100%">\n <el-table-column\n prop="name"\n label="姓名"\n width="180">\n </el-table-column>\n <el-table-column\n prop="age"\n label="年龄"\n width="180">\n </el-table-column>\n <el-table-column\n prop="address"\n label="地址"\n :span-method="spanMethod">\n </el-table-column>\n </el-table>\n <el-pagination\n @size-change="handleSizeChange"\n @current-change="handleCurrentChange"\n :current-page="currentPage"\n :page-sizes="[10, 20, 30, 40]"\n :page-size="pageSize"\n layout="total, sizes, prev, pager, next, jumper"\n :total="total">\n </el-pagination>\n </div>\n</template>\n\n<script>\nexport default {\n data() {\n return {\n tableData: [\n { name: "张三", age: 18, address: "北京市" },\n { name: "李四", age: 22, address: "上海市" },\n { name: "王五", age: 20, address: "广州市" },\n { name: "赵六", age: 25, address: "深圳市" },\n { name: "钱七", age: 28, address: "重庆市" }\n ],\n currentPage: 1,\n pageSize: 10,\n total: 5\n };\n },\n methods: {\n spanMethod({ row, column, rowIndex, columnIndex }) {\n if (columnIndex === 2) {\n if (rowIndex === 0) {\n return {\n rowspan: 2,\n colspan: 1\n };\n } else {\n return {\n rowspan: 0,\n colspan: 0\n };\n } \n }\n },\n handleSizeChange(val) {\n this.pageSize = val;\n },\n handleCurrentChange(val) {\n this.currentPage = val;\n }\n }\n};\n</script>\n\n这个示例中包含一个<code>el-table</code>组件用于展示数据,其中的<code>el-table-column</code>组件中的<code>:span-method</code>属性用于合并列。同时还有一个<code>el-pagination</code>组件用于分页,通过监听<code>size-change</code>和<code>current-change</code>事件来更新当前页和每页显示数量。\n\n注意:在使用该代码之前,需要先确保已经安装了Vue.js和Element UI,并正确引入了相关的文件。</p>
AI 优化版
原文地址:https://www.cveoy.top/t/topic/pERs 著作权归作者所有。请勿转载和采集!