当前位置: 首页 > news >正文

Vue+Element 封装表格组件

场景:

web项目开发离不开表格数据展示,还有其他定制化的样式及功能

如果每个页面都直接使用组件库的表格,会使项目代码过于臃肿

于是,封装一个表格组件,全局挂载,页面组件直接使用即可

实现:

vue2:

表格子组件:

<template><div><!-- 封装表格 --><el-table :data="tableData" @selection-change="selectionChange" :show-summary="showSummary" :sum-text="sumText" :stripe="isStripe"border fit :summary-method="getSummaries" :max-height="maxHeight" style="width: 100%" v-loading="isLoading"><!-- 表头 --><template v-for="item in tableHead"><!-- 序号 --><el-table-column v-if="item.type && item.type=='index'" :label="item.label" :key="item.type" :type="item.type" align="center"header-align="center" width="50px"></el-table-column><!-- 复选框 --><el-table-column v-if="item.type && item.type=='selection'" fit="true" :key="item.type" :type="item.type" align="center"header-align="center" :filter-multiple="true"></el-table-column><!-- 操作列 --><el-table-column v-if="item.prop == 'operation'" fit="true" :key="item.label" :label="item.label" :prop="item.prop" align="center"header-align="center" :filter-multiple="true" :width="item.width || '150'"><template slot-scope="{row}"><div class="btns_div"><el-link v-for="i in item.list" :key="i.prop" :type="i.lineType && i.lineType(row)" @click="i.handlerFn(row, i.prop)" :disabled="i.flagDisabledFn && i.flagDisabledFn(row)">{{ (i.handlerLabel && i.handlerLabel(row)) || i.label}}</el-link></div></template></el-table-column><!-- 数据列 --><el-table-column v-if="item.prop != 'operation' && item.type!='selection' && item.type!='index'" fit="true" :key="item.label":label="item.label" :prop="item.prop" align="center" header-align="center" :filter-multiple="true" show-overflow-tooltip:min-width="item.minWidth || '150'"><!-- 表头内容:优先使用外部插槽,其次用默认提示信息 --><template slot="header"><!-- 外部自定义表头插槽 --><template v-if="item.slotName"><slot :name="`header_${item.slotName}`" :item="item"></slot></template><!-- 默认表头 --><template v-else><span>{{ item.label }}</span></template></template><!-- 数据展示 --><template slot-scope="{row}"><!-- 使用自定义插槽(如果配置了slotName) --><template v-if="item.slotName"><!-- 动态插槽名称:使用item.slotName,方便外部传入自定义内容 --><slot :name="item.slotName" :row="row"></slot></template><!-- 特殊数据处理 --><span v-if="item.formatData">{{item.formatData(row) }}</span><!-- 不用处理的数据 --><span v-else>{{row[item.prop]}}</span></template></el-table-column></template></el-table>
http://www.dtcms.com/a/545305.html

相关文章:

  • 有向图能拓扑排序,必定无环
  • 网络:2.1加餐 - 网络命令
  • 为什么需要设置字符编码?
  • 电影网站如何做seo济南制作公司网站
  • 怎么网站排名seo乐清网络推广公司
  • 仓颉 String 内存表示:从 UTF-8 小对象到零拷贝子串的完整旅程
  • Android Studio新手开发第三十四天
  • 多维c++ vector, vector<pair<int,int>>, vector<vector<pair<int,int>>>示例
  • 【TVM 教程】自定义优化
  • 免费行情网站大全下载成品源码网站
  • 男女生做羞羞事情的网站网站域名怎样选择
  • 做政协网站软件的公司找人做网站 优帮云
  • 电力系统安全新样本:瑞数信息用“动态安全”筑起业务防线
  • 基于Python(Tkinter)实现(图形界面)小说阅读器
  • 选ThinkPad还是ThinkBook?联想乐享智能体让你告别选择困难!
  • 企业网站seo优化怎么做个人网站建设小江
  • 4种智能方法:如何将SIM卡中的短信转移到电脑
  • 【2D/3D户型图编辑器实现-技术栈选择】附demo演示
  • 信息网站开发网络公司人工智能公众号
  • SpringBoot15-项目部署
  • 安卓玩机工具推荐------ROOT与免ROOT安卓设备玩机工具
  • 【视觉slam十四讲】【十二讲 建图】12.1 习题:证明两个正态分布的联合分布
  • 【大数据高并发核心场景实战】 数据持久化层 - 查询分离
  • 一键阿里云 wordpress在门户网站做产品seo
  • 互联网站建设机构搭建网站大概多少钱
  • JavaScript DOM节点操作详解
  • Ultralytics 代码库深度解读【三】:YOLO V8/V11 核心模块可视化拆解(网络结构与参数解析)
  • 佰力博检测与您探讨压电陶瓷圆柱纵向振动模式
  • 32岁学做网站石家庄网站建设平台有哪些
  • 基于 51 单片机的智能手势控制小车设计与实现