在开发过程中,我遇到了一个需求,就是有两个表格,点击 表格1 的行 动态加载 表格2 的内容,同时,表格1 被点击的行需要高亮显示。由于有两个表格,所以我给每个表格都加了一个 key 值,但是,我按照官网的文档设置了 :row-config="{isCurrent: true, isHover: true}" 属性,可是当点击的时候,高亮行仍然不会显示
解决方法:把需要有 高亮行 的那个表格 的 key 值去掉就好了
案例代码:
<template>
<div>
<!-- 把下面这个表格的 :key="Math.random()" 删除就可以了-->
<vxe-table :key="Math.random()"
border
ref="xTable"
height="300"
:row-config="{isCurrent: true, isHover: true}"
:data="tableData"
@current-change="currentChangeEvent">
<vxe-column field="name"
title="Name"></vxe-column>
<vxe-column field="sex"
title="Sex"></vxe-column>
<vxe-column field="age"
title="Age"></vxe-column>
<vxe-column field="address"
title="Address"
show-overflow></vxe-column>
</vxe-table>
<!-- 下面这个表格的 :key="Math.random()" 不用删 -->
<vxe-table :key="Math.random()"
border
ref="xTable"
height="300"
:row-config="{isCurrent: true, isHover: true}"
:data="tableData1">
<vxe-column field="name"
title="Name"></vxe-column>
<vxe-column field="sex"
title="Sex"></vxe-column>
<vxe-column field="age"
title="Age"></vxe-column>
<vxe-column field="address"
title="Address"
show-overflow></vxe-column>
</vxe-table>
</div>
</template>
<script>
export default {
data () {
return {
tableData: [
{ id: 10001, name: 'Test1', role: 'Develop', sex: 'Man', age: 28, address: 'test abc' },
{ id: 10002, name: 'Test2', role: 'Test', sex: 'Women', age: 22, address: 'Guangzhou' },
{ id: 10003, name: 'Test3', role: 'PM', sex: 'Man', age: 32, address: 'Shanghai' },
{ id: 10004, name: 'Test4', role: 'Designer', sex: 'Women', age: 24, address: 'Shanghai' }
],
tableData1: []
}
},
methods: {
currentChangeEvent ({ row }) {
console.log(row)
// 模拟请求动态获取 表格2 的表格数据
setTimeout(() => {
this.tableData1 = [
{ id: 10005, name: 'Test5', role: 'Develop', sex: 'Man', age: 28, address: 'test abc' },
{ id: 10006, name: 'Test6', role: 'Test', sex: 'Women', age: 22, address: 'Guangzhou' },
{ id: 10007, name: 'Test7', role: 'PM', sex: 'Man', age: 32, address: 'Shanghai' },
{ id: 10008, name: 'Test8', role: 'Designer', sex: 'Women', age: 24, address: 'Shanghai' }
]
}, 100)
}
}
}
</script>
<style>
</style>