element封装表格
<template>
<div>
<el-scrollbar class="table-wrap">
<el-table
v-loading="loading"
:data="tableData"
:height="height"
:stripe="stripe"
:border="border"
:max-height="maxHeight"
:header-cell-style="tabHeadStyle"
:cell-style="tabcellStyle"
:row-style="rowStyle"
style="width: 100%"
@selection-change="handleSelectionChange"
>
<!-- 多选 -->
<el-table-column
v-if="isSelection"
type="selection"
align="center"
:is-selection="selectable"
/>
<!-- 索引 -->
<el-table-column
v-if="isIndex"
:label="indexLabel"
type="index"
align="center"
width="50"
/>
<template v-for="(item, index) in tableCols">
<!-- 合并单元格 -->
<el-table-column
v-if="item.type == 'table_column'"
:key="index"
:label="item.label"
:width="item.width"
:min-width="item['min-width']"
:fixed="item.fixed"
:align="item.align"
:header-align="item['header-align'] || 'left'"
:show-overflow-tooltip="item['show-overflow-tooltip'] || true"
>
<!-- <el-table-column
v-for="(itema, index) in item.prop"
:key="index"
:label="itema.label"
:prop="itema.prop"
:width="itema.width"
:min-width="itema['min-width']"
:fixed="itema.fixed"
:align="itema.align"
:header-align="itema['header-align'] || 'left'"
:show-overflow-tooltip="itema['show-overflow-tooltip'] || true"
>
<template v-if="itema.slot" slot-scope="scope" :name="itema.slot">
<slot :name="itema.slot" :row="scope.row" />
</template>
</el-table-column> -->
<el-table-column
v-for="(itema, index) in item.prop"
:key="index"
:label="itema.label"
:prop="itema.prop"
:width="itema.width"
:min-width="itema['min-width']"
:fixed="itema.fixed"
:align="itema.align"
:header-align="itema['header-align'] || 'left'"
:show-overflow-tooltip="itema['show-overflow-tooltip'] || true"
/>
</el-table-column>
<!-- 需要插槽 -->
<el-table-column
v-if="item.slot && !item.type"
:key="index"
:label="item.label"
:prop="item.prop"
:width="item.width"
:min-width="item['min-width']"
:fixed="item.fixed"
:align="item.align"
:header-align="item['header-align'] || 'left'"
:show-overflow-tooltip="item['show-overflow-tooltip'] || true"
>
<template v-if="item.slot" slot-scope="scope" :name="item.slot">
<slot :name="item.slot" :row="scope.row" />
</template>
</el-table-column>
<!--不需要插槽-->
<el-table-column
v-if="!item.slot && !item.type"
:key="index"
:label="item.label"
:prop="item.prop"
:width="item.width"
:min-width="item['min-width']"
:fixed="item.fixed"
:align="item.align"
:header-align="item['header-align'] || 'left'"
:show-overflow-tooltip="item['show-overflow-tooltip'] || true"
/>
</template>
</el-table>
</el-scrollbar>
<el-pagination
v-if="pagInationIf"
:current-page="pagInation.pageNum"
:total="pagInation.count"
:page-size="pagInation.pageSize"
layout="prev, pager, next,total"
background
@current-change="handleCurrentChange"
/>
</div>
</template> <script type="text/ecmascript-6">
export default {
name: 'SirTable',
props: {
// 加载状态
loading: { type: Boolean, default: false },
// 表格列配置
tableCols: { type: [Array], default: () => [] },
// 表格内数据
tableData: { type: [Array], default: () => [] },
// 表格是否显示斑马线
stripe: { type: [Boolean, String], default: false },
// 表格边框
border: { type: [Boolean, String], default: false },
height: { type: [Number, String], default: null },
// 最大高度
maxHeight: { type: [Number, String], default: null },
// 是否显示表格复选框
isSelection: { type: [Boolean], default: false },
// 是否显示表格索引
isIndex: { type: Boolean, default: true },
// 索引lable
indexLabel: { type: String, default: '序号' },
// 分页数据
pagInation: { type: Object, default: () => ({ pageSize: 10, pageNo: 1, total: 0 }) },
pagInationIf: { type: [Boolean], default: true },
},
data() {
return {
// 表头样式
tabHeadStyle: {
'background-color': '#FAFAFA',
color: '#333333', 'font-weight': 'bold'
},
// 行样式
tabcellStyle: {
color: '#666'
},
rowStyle: {
height: '50px'
}
}
},
methods: {
// 据条件禁用某个列表项的选择框
selectable(row) {
if ((row.prohibit == null) || (row.prohibit == '')) {
return true
} else {
return false
}
},
// 多选事件,保存选择项到指定参数
handleSelectionChange(val) {
this.$emit('checkbox-data', val)
},
// 翻页触发
handleCurrentChange(val) {
this.pagInation.pageNum = val
this.$emit('refresh', this.pagInation) }
}
}
</script> <style lang="scss" scoped>
.el-table td {
/*min-height: 40px;*/
/*padding: 0 !important;*/
}
/deep/.el-table--enable-row-transition .el-table__body td {
min-height: 40px;
padding: 0;
}
/deep/.el-scrollbar__wrap {
height: $tableCalc;
}
/*分页*/
.el-pagination {
float: right;
margin-top: 25px;
}
/deep/.el-pagination.is-background {
.number,
.btn-prev,
.btn-next {
background-color: #fff;
border: 1px solid #ebedf0;
}
.el-pager li {
background-color: #fff;
}
}
/deep/.el-pagination.is-background .el-pager li:not(.disabled):hover {
color: #499bfc;
}
/deep/.el-pagination.is-background .el-pager li:not(.disabled).active {
background-color: #499bfc;
color: #fff;
}
</style>
element封装表格的更多相关文章
- element el-table表格的vue组件二次封装(附表格高度自适应)
基于vue的el-table表格二次封装组件方法 前言 在公司实习使用vue+element-ui框架进行前端开发,使用表格el-table较为多,有些业务逻辑比较相似,有些地方使用的重复性高,如果多 ...
- 前端枚举enum的应用(Element)封装
什么是枚举Enum 枚举 Enum是在众多语言中都有的一种数据类型,JavaScript中还没有(TypeScript有).用来表示一些特定类别的常量数据,如性别.学历.方向.账户状态等,项目开发中是 ...
- element ui 表格提交时获取所有选中的checkbox的数据
<el-table ref="multipleTable" :data="appList" @selection-change="changeF ...
- 封装一个优雅的element ui表格组件
现在做后台系统用vue + elementUI 的越来越多,那element ui的 el-table 组件肯定也离不开.虽然element ui的table组件很好.但是表格和分页是分离的.每次写表 ...
- vue2.0+Element UI 表格前端分页和后端分页
之前写过一篇博客,当时对element ui框架还不太了解,分页组件用 html + css 自己写的,比较麻烦,而且只提到了后端分页 (见 https://www.cnblogs.com/zdd20 ...
- vue + element ui 表格自定义表头,提供线上demo
前言:工作中用到 vue+element ui 的前端框架,需要使用自定义表头,需要使用 re.转载请注明出处:https://www.cnblogs.com/yuxiaole/p/9710826.h ...
- Element UI表格组件技巧:如何简洁实现跨页勾选、跨页统计功能
业务场景 在使用Element UI的Table组件时,常常面对这样的业务需求: 表格数据的每一项都要提供勾选框,当切换分页时,能够记忆所有页面勾选的数据,以实现批量提交不同页面勾选数据的功能.并且, ...
- element UI表格行高、padding等设置报错问题
element UI里面表格的行高需要自己调整高度和设置padding,直接写style是不行的,里面有 : 1.row-style (行的 style) 2.header-row-styl (表 ...
- 手把手教学~基于element封装tree树状下拉框
在日常项目开发中,树状下拉框的需求还是比较常见的,但是element并没有这种组件以供使用.在这里,小编就基于element如何封装一个树状下拉框做个详细的介绍. 通过这篇文章,你可以了解学习到一个树 ...
随机推荐
- 【Mysql】SpringBoot阿里Druid数据源连接池配置
一.pom.xml添加 <!-- 配置数据库连接池 --> <dependency> <groupId>com.alibaba</groupId> &l ...
- Take C# 8.0 for a spin
本文章为机器翻译.https://blogs.msdn.microsoft.com/dotnet/2018/12/05/take-c-8-0-for-a-spin/ 以C # 8兜风 我们昨天宣布Vi ...
- C#LeetCode刷题之#414-第三大的数(Third Maximum Number)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3710 访问. 给定一个非空数组,返回此数组中第三大的数.如果不存 ...
- C#LeetCode刷题之#66-加一(Plus One)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3684 访问. 给定一个由整数组成的非空数组所表示的非负整数,在该 ...
- Android 开发学习进程0.11 pageview relativelayout 沉浸式标题栏
fragment与pageView fragment fragment不可以侧滑切换相关界面,但多数代码位于fragment中,易于维护,同时不会受到多个手势滑动的影响 pageView pageVi ...
- python设计模式之模型-视图-控制器模式
python设计模式之模型-视图-控制器模式 关注点分离( Separation of Concerns, SoC)原则是软件工程相关的设计原则之一. SoC原则背后的思想是将一个应用切分成不同的部分 ...
- 生成kafka内部请求与响应的接口文档
生成kafka内部请求与响应的接口文档 /** */ package com.code260.ss.kafka10demo; import java.io.File; import java.io.I ...
- css两种常用的不定宽高的水平垂直居中方法,记住它,不再为样式发愁
css 几种常用的简单容易记住的水平垂直居中方法 前言 正文 第一种方法 第二种方法 结束语 前言 我们在设计网页时,会大量的运用到水平垂直居中,如果知道元素的宽高,那水平垂直居中是很简单的,无非是用 ...
- Docker 的前世今生
虚拟化 「要解释清楚 Docker,首先要解释清楚容器(Container)的概念」.要解释容器的话,就需要从操作系统说起.操作系统太底层,细说的话一两本书都说不清楚.这里就一句话来总结一下:操作系统 ...
- Arraylist的源码学习
@ 目录 ArrayList简介 ArrayList核心源码 ArrayList源码分析 System.arraycopy()和Arrays.copyOf()方法 两者联系与区别 ArrayList ...