<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封装表格的更多相关文章

  1. element el-table表格的vue组件二次封装(附表格高度自适应)

    基于vue的el-table表格二次封装组件方法 前言 在公司实习使用vue+element-ui框架进行前端开发,使用表格el-table较为多,有些业务逻辑比较相似,有些地方使用的重复性高,如果多 ...

  2. 前端枚举enum的应用(Element)封装

    什么是枚举Enum 枚举 Enum是在众多语言中都有的一种数据类型,JavaScript中还没有(TypeScript有).用来表示一些特定类别的常量数据,如性别.学历.方向.账户状态等,项目开发中是 ...

  3. element ui 表格提交时获取所有选中的checkbox的数据

    <el-table ref="multipleTable" :data="appList" @selection-change="changeF ...

  4. 封装一个优雅的element ui表格组件

    现在做后台系统用vue + elementUI 的越来越多,那element ui的 el-table 组件肯定也离不开.虽然element ui的table组件很好.但是表格和分页是分离的.每次写表 ...

  5. vue2.0+Element UI 表格前端分页和后端分页

    之前写过一篇博客,当时对element ui框架还不太了解,分页组件用 html + css 自己写的,比较麻烦,而且只提到了后端分页 (见 https://www.cnblogs.com/zdd20 ...

  6. vue + element ui 表格自定义表头,提供线上demo

    前言:工作中用到 vue+element ui 的前端框架,需要使用自定义表头,需要使用 re.转载请注明出处:https://www.cnblogs.com/yuxiaole/p/9710826.h ...

  7. Element UI表格组件技巧:如何简洁实现跨页勾选、跨页统计功能

    业务场景 在使用Element UI的Table组件时,常常面对这样的业务需求: 表格数据的每一项都要提供勾选框,当切换分页时,能够记忆所有页面勾选的数据,以实现批量提交不同页面勾选数据的功能.并且, ...

  8. element UI表格行高、padding等设置报错问题

    element UI里面表格的行高需要自己调整高度和设置padding,直接写style是不行的,里面有 : 1.row-style (行的 style) 2.header-row-styl   (表 ...

  9. 手把手教学~基于element封装tree树状下拉框

    在日常项目开发中,树状下拉框的需求还是比较常见的,但是element并没有这种组件以供使用.在这里,小编就基于element如何封装一个树状下拉框做个详细的介绍. 通过这篇文章,你可以了解学习到一个树 ...

随机推荐

  1. 【Spring Security】1.快速入门

    1 导入Spring Security的相关依赖 <dependency> <groupId>org.springframework.boot</groupId> ...

  2. 微信小程序携带参数跳转页面/获取页面栈

    页面跳转携带参数(以传递两个参数为例) a.wxml 页面传递 1 <navigator url="/pages/b/b?id=1&sid='289'"> &l ...

  3. MacOS抓包工具Charles

    抓包工具有wireshark, tcpdump, 还有就是Charles. 今天分享的是最后一个Charles.抓包分2个, 一个是移动端的,一个是macOS自带的应用. 安装Charles http ...

  4. Testflight无法接入App Store connect,对TF上架的应用会造成什么影响吗?

    感觉进入8月份以来,苹果也进入了多事之秋.不仅是App Store被下架,testflight也频频出问题,很多人反馈出现了Testflight无法接入App Store connect的问题,我们之 ...

  5. 送大家几个cnblogs号,供快捷评论,请谨慎使用

    欢迎评论& 3461896724@qq.com互动 可以在我的首页看更多 #1先送大家几个号:(密码都是 MLdlight2020)请区分大小写(可以直接复制) 写过一篇 免费验证码接收网站& ...

  6. 笔记:Linux下软件的安装、CentOS更新yum源、LAMP环境搭建、kali软件管理

    一.Linux下软件的安装 方式:yum源 / rpm /源码安装 1.yum:(帮助管理员解决依赖关系) yum是通过分析rpm的包头数据后,根据各种软件的相关性质做出属性相对应的解决方案,然后可以 ...

  7. python基础 Day3

    python Day3 1.作业回顾 设定一个理想的数字比如88,让用户输入数字,如果比88大,则显示猜测的结果大:如果比66小,则显示猜测的结果小了,给用户三次猜测机会,如果显示猜测正确退出循环,如 ...

  8. 第2章 执行SparkSQL查询

    第2章 执行SparkSQL查询 2.1 命令行查询流程 打开Spark shell 例子:查询大于30岁的用户 创建如下JSON文件,注意JSON的格式: {"name":&qu ...

  9. 精讲响应式WebClient第3篇-POST、DELETE、PUT方法使用

    本文是精讲响应式WebClient第3篇,前篇的blog访问地址如下: 精讲响应式webclient第1篇-响应式非阻塞IO与基础用法 精讲响应式WebClient第2篇-GET请求阻塞与非阻塞调用方 ...

  10. Play it again: reactivation of waking experience and memory

    郑重声明:原文参见标题,如有侵权,请联系作者,将会撤销发布! Trends in Neurosciences, no. 5 (2010): 220-229 Abstract 回合空间记忆均涉及海马体神 ...