element plus table 单选
时间: 2023-11-12 19:07:20 浏览: 214
要实现 element plus table 单选,需要在 el-table 上设置 :row-key 和 @selection-change 两个属性。其中 :row-key 用于指定每行数据的唯一标识,@selection-change 用于监听选中项的变化。具体实现可以参考以下代码:
```html
<template>
<el-table
:data="tableData"
:row-key="row => row.id"
@selection-change="handleSelectionChange"
:selectable="row => !row.disabled"
v-model="selectedRows"
style="width: 100%">
<el-table-column
type="selection"
width="55">
</el-table-column>
<el-table-column
prop="name"
label="姓名">
</el-table-column>
<el-table-column
prop="age"
label="年龄">
</el-table-column>
</el-table>
</template>
<script>
export default {
data() {
return {
tableData: [
{ id: 1, name: '张三', age: 18, disabled: false },
{ id: 2, name: '李四', age: 20, disabled: true },
{ id: 3, name: '王五', age: 22, disabled: false },
{ id: 4, name: '赵六', age: 24, disabled: false }
],
selectedRows: []
}
},
methods: {
handleSelectionChange(selectedRows) {
this.selectedRows = selectedRows
}
}
}
</script>
```
阅读全文