手机版企业网站php,百度网盘网页版入口,简单网上书店网站建设php,灯光设计网站推荐最近的项目中使用到element-ui组件库#xff0c;由于做的是后台管理系统#xff0c;所以经常需要操作表格#xff0c;编辑样式的过程中遇到一些问题#xff0c;官网针对table给出了很多的api#xff0c;自己可以自定义#xff0c;基本能满足产品需求#xff0c;但是没有… 最近的项目中使用到element-ui组件库由于做的是后台管理系统所以经常需要操作表格编辑样式的过程中遇到一些问题官网针对table给出了很多的api自己可以自定义基本能满足产品需求但是没有给出具体的案例网上的资料也比较简略这里简单整理下一些常用的操作如果有类似的功能可以做一个参考。 具体的使用方法还是建议仔细阅读官网-table章节 https://element.eleme.cn/#/zh-CN/component/table#table-column-scoped-slot 该项目demo已上传github欢迎大家下载
# 克隆到本地
git clone gitgithub.com:Hanxueqing/Element-table.git# 安装依赖
npm install# 开启本地服务器localhost
npm run dev项目地址 https://github.com/Hanxueqing/Element-table
自定义列的内容 需求在表格最后一栏添加操作按钮 通过slot-scopescope添加操作按钮这是专门为我们提供的插槽方便自定义添加不同的内容。
el-table-column label操作 width160template slot-scopescopeel-button sizemini typeprimary plain click showIndex(scope.$index)点击显示当前行下标/el-button/template
/el-table-column根据下标可以对指定某一行进行操作 scope.row 获取当前属性值 通过scope.row属性名可以获取当前行对应的属性值
el-table-column label操作 width160template slot-scopescopeel-button sizemini typeprimary plain click showName(scope.row.name)点击获取姓名属性/el-button/template
/el-table-column可以通过scope.row属性名和三目运算符给特殊的属性值设定样式
el-table-column propname :labellangConfig.table.name[lang] width200template slot-scopescopediv :classscope.row.name 王大虎 ? specialColor:{{scope.row.name}}/div/template
/el-table-column编写specialColor样式将字体颜色设置为红色
.specialColor{color:red;}设置表头样式 需求将表头样式改为背景色蓝色字体颜色白色字重400 header-cell-class-name 说明表头单元格的 className 的回调方法也可以使用字符串为所有表头单元格设置一个固定的 className。
类型Function({row, column, rowIndex, columnIndex})/String
函数形式将headerStyle方法传递给header-cell-class-name
el-table :datatableData[lang] classtable stripe border :header-cell-class-nameheaderStyle编写headerStyle返回class名称tableStyle
headerStyle ({row, column, rowIndex, columnIndex}) {return tableStyle}在style中编写tableStyle样式
style lang scss.tableStyle{background-color: #1989fa!important;color:#fff;font-weight:400;}
/style字符串形式直接将tableStyle名称赋值给header-cell-class-name
el-table :datatableData[lang] classtable stripe border header-cell-class-nametableStyleheader-cell-style 说明表头单元格的 style 的回调方法也可以使用一个固定的 Object 为所有表头单元格设置一样的 Style。
类型Function({row, column, rowIndex, columnIndex})/Object
函数形式将tableHeaderStyle方法传递给header-cell-style
el-table :datatableData[lang] classtable stripe border :header-cell-styletableHeaderStyle编写tableHeaderStyle方法返回样式
tableHeaderStyle ({row, column, rowIndex, columnIndex}) {return background-color:#1989fa;color:#fff;font-weight:400;}对象形式直接在对象中编写样式
el-table :datatableData[lang] classtable stripe border :header-cell-style{background-color: #1989fa,color: #fff,font-weight: 400}header-row-class-name 说明表头行的className 的回调方法也可以使用字符串为所有表头行设置一个固定的 className。
类型Function({row, rowIndex})/String
使用方式与header-cell-class-name类似
注意header-row-class-name与header-cell-class-name的区别 header-row-class-name是添加在tr上面的header-cell-class-name是添加在th上面的。 header-row-class-name: 所以想让添加在tr上的样式显示需要关闭element-ui中原本的th的样式否则会被覆盖例如背景色 header-cell-class-name: header-row-style 说明表头行的 style 的回调方法也可以使用一个固定的 Object 为所有表头行设置一样的 Style。
类型Function({row, rowIndex})/Object
使用方式与header-cell-style类似
设置行样式 需求将表格中行的背景色设置为浅蓝色 row-class-name 说明行的 className 的回调方法也可以使用字符串为所有行设置一个固定的 className。
类型Function({row, rowIndex})/String
使用方式与header-cell-class-name类似
row-style 说明行的 style 的回调方法也可以使用一个固定的 Object 为所有行设置一样的 Style。
类型Function({row, rowIndex})/Object
使用方式与header-cell-style类似
函数形式将tableRowStyle方法传给row-style
el-table :datatableData[lang] classtable border :row-styletableRowStyle编写tableRowStyle方法返回样式
// 修改table tr行的背景色tableRowStyle ({ row, rowIndex }) {return background-color:#ecf5ff}点击按钮操作当前行 需求点击操作栏的按钮切换按钮状态并且将当前行置灰 通过slot-scope添加按钮
el-table-column label操作 width160template slot-scopescopeel-button sizemini typedanger plain v-if scope.row.buttonVisible click changeTable(scope.row.buttonVisible,scope.$index)禁用该行/el-buttonel-button sizemini typeprimary plain v-else click changeTable(scope.row.buttonVisible,scope.$index)启用该行/el-button/template
/el-table-column在每一个data中添加buttonVisible字段使用v-if/v-else指令实现按钮的显示与隐藏
{date: 2016-05-10,name: 王大虎,address: 上海市普陀区金沙江路 1518 弄,zip: 200333,buttonVisible: true
}编写changeTable方法点击按钮的时候更改buttonVisible的值
changeTable (buttonVisible, index) {this.tableData[index].buttonVisible !buttonVisible
}给el-table添加row-style并且将tableRowStyle方法传递给row-style
el-table :datatableData classtable border :row-styletableRowStyle编写tableRowStyle方法根据每一行buttonVisible的值设置背景色
// 修改table tr行的背景色tableRowStyle ({ row, rowIndex }) {if (this.tableData[rowIndex].buttonVisible false) {return background-color: rgba(243,243,243,1)}}Element-UI中关于table表格的那些骚操作