vue.js - How do I use cell-class-name of el-table correctly?
问题描述
I want to use cell-class-name to change the styling of individual cells based on the row and column of the specific cell.
As a minimal example I however just try to apply the same selected-cell
-styling to every cell. Unfortunately, there's no effect through setting cell-class-name .
<template>
<div>
<el-table :data="myTable" :cell-class-name="cellStyle">
<el-table-column prop="name" label="name" width="115"/>
<el-table-column prop="occupation" label="occupation" align="right" width="115"/>
</el-table>
</div>
</template>
<script>
import { Table, TableColumn } from "element-ui";
export default {
components: {
"el-table": Table,
"el-table-column": TableColumn
},
name: "HelloWorld",
data() {
return {
myTable: [
{
name: "jhon",
occupation: "Lawyer"
},
{
name: "Tom",
occupation: "Judge"
}
]
};
},
methods: {
cellStyle() {
return "selected-cell"
}
},
props: {
msg: String
}
};
</script>
<style scoped>
.selected-cell {
background: red;
color: red;
}
</style>
https://codesandbox.io/s/element-ui-table-header-issue-1jdvu?fontsize=14&hidenavigation=1&theme=dark
解决方案
从标签中删除scoped
属性style
应该可以修复它。
您可以通过以下方式将它们分开:
<style>
.selected-cell {
background: red;
color: red;
}
</style>
<style scoped>
/* other styles here*/
</style>
推荐阅读
- python - 代码在 Python 文件中工作,而不是在 Jupyter Notebook 中
- java - 无法将文件保存到android中的外部存储目录
- angular - 在量角器中调用 getText() 时,ElementFinder 正在记录
- android - 如何在操作系统默认查看器中的 React Native 应用程序中显示图像?
- debugging - 为什么在 64 位 Windows 下使用 ApplicationVerifier 进行堆调试时,会将 32 位进程限制为 2 GiB 的虚拟内存?
- angular - Angular - 找出派生类是否实现了抽象类(router.component)
- c# - 使用 OwnerDrawText 模式定位和突出显示 TreeView 节点文本
- php - 在php中对具有来自同一数组的多个依赖项的数组项进行排序
- xml - 如何使用 Xmlint 从 XML 文件映射某个值?
- angular-material - 如何更改 matInput 占位符的颜色?