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如何封装一个树状下拉框做个详细的介绍. 通过这篇文章,你可以了解学习到一个树 ...
随机推荐
- AndroidStudio新建项目报错build failed
AndroidStudio新建项目报错build failed 报错信息 org.gradle.initialization.ReportedException: org.gradle.interna ...
- realm数据库报错:Changing Realm data can only be done from inside a transaction.
在编写realm数据库相关时: 代码: List<Student> delByStudent(String priNum){ RealmResults<Student> stu ...
- SpringMVC实现客户端跳转
之前无论是/index跳转到index.jsp 还是/addProduct 跳转到showProduct.jsp,都是服务端跳转. 这一篇练习如何进行客户端跳转 @ 目录 修改IndexControl ...
- JavaScript学习系列博客_35_JavaScript 正则表达式的使用
正则表达式的使用 先说RegExp对象的一个方法 test() - 使用这个方法可以用来检查一个字符串是否符合正则表达式的规则,如果符合则返回true,否则返回false. 1.用正则表达式来检查一个 ...
- JavaScript学习系列博客_14_JavaScript中对象的基本操作
对象的基本操作 - 创建对象 - 方式一:使用new关键字调用的函数,是构造函数(constructor),构造函数是专门用来创建对象的函数. var obj = new Object(); - 方式 ...
- Invalid credentials for 'https://repo.magento.com/packages.json'
Use your public key as username and private key as password from your magento connect account You ca ...
- Python Jinja2 Template: YAML File Cisco Example Tutorial
原文链接:http://networkbit.ch/python-jinja-template/ template.txt如下: hostname {{ name }} interface Loopb ...
- ping通网关 ping不通dns
一.Request Timed Out 当Ping指定的对象时,出现“Request Timed Out”提示信息的频率非常高,这说明对方无法接受发送过来的数据.当然这种情况下,很可能就是网络出现了故 ...
- windows下cmd命令行计算文件hash值
命令:certutil -hashfile certutil -hashfile D:\.exe MD5 certutil -hashfile D:\.exe SHA1 certutil -hashf ...
- codeforce Round #605(Div.3)
A. Three Friends 题目链接 题目意思:有三个好朋友a,b,c.他们在一个坐标轴上,他们的位置分别是xa 和xb ,xc,他们三个人都可以往前或者往后走一步,只能走一步.问你他们走了(也 ...