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

vue3+elementui实现表格样式可配置

后端接口传回的数据格式如下图
在这里插入图片描述需要依靠后端传回的数据控制表格样式

实现代码

<!-- 可视化配置-表格 -->
<template><div class="tabulation_main" ref="myDiv"><!-- 尝试过在mounted中使用this.$refs.myDiv.offsetHeight,获取父元素高度赋值给height的方法,发现该值只能在created之前确定,且不为动态 --><el-table:data="tableData":stripe="tableStyleObj.tableStyle.stripe == 'true' ? true : false":row-style="rowStyleHandle":row-class-name="tableRowClassName":border="tableStyleObj.tableStyle.border == 'true' ? true : false"v-model:align="tableStyleObj.tableStyle.bodyTextAlign":show-header="tableStyleObj.tableStyle.showHeader == 'true' ? true : false":header-cell-style="{color: tableStyleObj.tableStyle.headerColor,'font-size': tableStyleObj.tableStyle.headerFontSize + 'px','text-align': tableStyleObj.tableStyle.headerTextAlign,}":header-row-class-name="headerRowClassName":height="tableStyleObj.tableStyle.tableHeight + ''"style="width: 100%"><!-- 固定序号列 --><el-table-columnv-if="tableStyleObj.tableStyle.isShowTableIndex == 'true' ? true : false":fixed="tableStyleObj.tableStyle.isTableIndexFixed == 'true' ? true : false"type="index":width="tableStyleObj.tableStyle.tableIndexWidth + ''"></el-table-column><el-table-columnv-for="(tableItem, tableIndex) in tableStyleObj.tableColStyle":key="tableIndex":prop="tableItem.prop":label="tableItem.label":width="tableItem.width + ''"></el-table-column></el-table></div>
</template><script>
export default {data() {return {tableStyleObj: {// 表格整体样式tableStyle: {},// 表格列配置tableColStyle: [],},tableData: [],};},props: {flatteningCurrentItemForm: {type: Object,default: () => {return {};},},},computed: {nthColor() {return this.tableStyleObj.tableStyle.nthColor;},othColor() {return this.tableStyleObj.tableStyle.othColor;},headerBackground() {return this.tableStyleObj.tableStyle.headerBackground;},},created() {// 获取表格配置this.tableStyleObj.tableStyle = this.flatteningCurrentItemForm.attributeCaseMap;this.tableStyleObj.tableColStyle = JSON.parse(this.flatteningCurrentItemForm.attributeCaseMap.tableColstyle);// 获取表格数据tableDataSource({dataSource: this.flatteningCurrentItemForm.dataSource,}).then((res) => {this.tableData = res.data;});},methods: {headerRowClassName({ row, rowIndex }) {return "head-row";},rowStyleHandle({ row, rowIndex }) {// rowIndex从0开始if (rowIndex % 2 == 0) {// 奇数行var obj = {"text-align": this.tableStyleObj.tableStyle.bodyTextAlign,color: this.tableStyleObj.tableStyle.bodyColor,"font-size": this.tableStyleObj.tableStyle.bodyFontSize + "px",};return obj;} else {// 偶数行var obj = {"text-align": this.tableStyleObj.tableStyle.bodyTextAlign,color: this.tableStyleObj.tableStyle.bodyColor,"font-size": this.tableStyleObj.tableStyle.bodyFontSize + "px",};return obj;}},tableRowClassName({ row, rowIndex }) {if (rowIndex % 2 == 0) {return "even-row";} else {return "odd-row";}},},
};
</script><style scoped lang="scss">
.tabulation_main {// 表格表头::v-deep(.el-table .el-table__header-wrapper th),::v-deep(.el-table .el-table__fixed-header-wrapper th) {background-color: v-bind("headerBackground") !important;}// 表格斑马纹::v-deep(.even-row td) {background-color: v-bind("nthColor") !important;}::v-deep(.odd-row td) {background-color: v-bind("othColor") !important;}::v-deep(.el-table) {background-color: v-bind("nthColor") !important;}
}
</style>
http://www.lryc.cn/news/189183.html

相关文章:

  • x11截屏源码(ubuntu18.04)
  • 【ComfyUI】MacBook Pro 安装(Intel 集成显卡)
  • HTTPS 加密全过程
  • 联邦学习综述二
  • Idea本地跑flink任务时,总是重复消费kafka的数据(kafka->mysql)
  • 基于nodemailer实现邮件发送
  • 【PostgreSQL内核学习(十八)—— (数据库表参数)】
  • 区块链的两个核心概念之一签名, 另一个是共识.
  • wpf中prism框架切换页面
  • 正则表达式(Regular Expression)学习网址分享
  • 【已解决】socket.gaierror: [Errno -3] Temporary failure in name resolution
  • CUDA code=700(cudaErrorIllegalAddress) 报错与排查方法
  • 项目管理过程组
  • python每日一练(5)
  • 经典循环命题:百钱百鸡
  • IDEA使用模板创建webapp时,web.xml文件版本过低的一种解决方法
  • 在Openresty中使用lua语言向请求浏览器返回请求头User-Agent里边的值
  • Hive面试常见基础问题
  • 设计模式 - 观察者模式
  • 【自动驾驶】PETR/PETRv2/StreamPETR论文分析
  • GPT实战系列-Baichuan2本地化部署实战方案
  • 用netty实现简易rpc
  • 【计算机网络】第三章课后习题答案
  • cesium 地图蒙版遮罩效果
  • 根据前序遍历结果构造二叉搜索树
  • 微信小程序指定某个元素强制重新渲染
  • 国际教材概念基础
  • 2023全国大学生软件测试大赛开发者测试练习题满分答案(PairingHeap2023)
  • 介绍一下tokens
  • 机器学习、深度学习相关的项目集合【自行选择即可】