Vue Element 表格多选框选中字体变蓝加粗
<p>要实现表格多选框选中后字体颜色变蓝、加粗,可以通过自定义样式来实现。具体步骤如下:</p>
<ol>
<li>在表格组件所在的 .vue 文件中,添加以下样式:</li>
<pre><code class="language-css"><style scoped>
.el-table .is-checked {
color: blue;
font-weight: bold;
}
</style></code></pre>
<li>在表格的列定义中,使用 'header-checkbox' 插槽来自定义多选框的样式,并为选中的行添加 'is-checked' 类名,示例如下:</li>
<pre><code class="language-html"><el-table
:data="tableData"
style="width: 100%">
<el-table-column
type="selection"
width="55">
<template slot-scope="{ row }">
<el-checkbox v-model="selection" @change="handleSelectionChange(row)" :class="{ 'is-checked': selection.indexOf(row) > -1 }"></el-checkbox>
</template>
</el-table-column>
<!-- 其他列定义 -->
</el-table></code></pre>
<li>在组件的 'data' 中定义一个 'selection' 数组,用于存储选中的行数据:</li>
<pre><code class="language-javascript">data() {
return {
selection: []
};
},</code></pre>
<li>在 'handleSelectionChange' 方法中更新 'selection' 数组:</li>
<pre><code class="language-javascript">methods: {
handleSelectionChange(row) {
this.selection = row;
}
}</code></pre>
<p>这样,当多选框选中时,选中的行字体颜色会变为蓝色、加粗。</p>
原文地址: https://www.cveoy.top/t/topic/o972 著作权归作者所有。请勿转载和采集!