LDB*_*LDB 2 html javascript vue.js
我想在 Vuejs 中突出显示“@click”上的表格行。目前我在让它工作时遇到问题。
这是我的 html 模板,我将活动类绑定到布尔“isActive”。
<table
class="paginatedTable-table hide-table">
<thead class="paginatedTable-table-head">
<tr :class="{active: isActive}" class="paginatedTable-table-head-row">
<th
v-for="(column, key) in columns"
:key="key"
:class="column.align"
class="paginatedTable-table-head-row-header"
@click="sortTable(column)">
{{ column.label }}
<i
v-if="sortOptions.currentSortColumn === column.field"
:class="sortOptions.sortAscending ? icons.up : icons.down"
class="sort-icon" />
</th>
</tr>
Run Code Online (Sandbox Code Playgroud)
我在数据函数中声明 isActive 并设置为 false。
data() {
return {
width: '100%',
'marginLeft': '20px',
rowClicked: false,
filteredData: this.dataDetails,
isActive: false,
Run Code Online (Sandbox Code Playgroud)
我设置 isActive 为 true 的按钮单击功能
async selectRow(detail) {
this.isActive = true;
this.width = '72%';
this.rowClicked = true;
Run Code Online (Sandbox Code Playgroud)
这部分我不太确定。在这里,我在 Sass 中设置了 Css。
tr:not(.filters):not(.pagination-row) {
background-color: $white;
&.active{
background-color: $lc_lightPeriwinkle;
}
Run Code Online (Sandbox Code Playgroud)
例如,要遍历用户表,并在单击时突出显示 tr:
<table>
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<tr v-for="user in users" @click="selectRow(user.id)" :key="user.id" :class="{'highlight': (user.id == selectedUser)}">
<td>{{ user.id }}</td>
<td>{{ user.name }}</td>
<td>{{ user.email }}</td>
</tr>
</tbody>
</table>
Run Code Online (Sandbox Code Playgroud)
声明您的数据:
data(){
return {
users: [],
selectedUser: null
}
}
Run Code Online (Sandbox Code Playgroud)
在您的 selectRow 方法中;
selectRow(user){
this.selectedUser = user;
//Do other things
}
Run Code Online (Sandbox Code Playgroud)
然后你的班级:
. highlight {
background-color: red;
}
tr:hover{
cursor: pointer;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7459 次 |
| 最近记录: |