el-table代码勾选某一行
时间: 2023-10-14 13:44:22 浏览: 36
要在el-table中勾选某一行,你可以使用el-table组件提供的selection属性。首先,你需要在el-table中设置selection属性为一个数组,用于存储已选中的行的数据。然后,在el-table-column中添加type属性为"selection",这将在每一行前面显示一个复选框。最后,你可以使用@selection-change事件监听选择状态的变化,并在事件处理程序中更新选中的行数据。
以下是一个简单的示例代码:
```html
<template>
<el-table
:data="tableData"
:selection="selectedRows"
@selection-change="handleSelectionChange"
>
<el-table-column type="selection"></el-table-column>
<!-- 其他列定义 -->
</el-table>
</template>
<script>
export default {
data() {
return {
tableData: [
// 表格数据
],
selectedRows: [] // 存储选中行数据的数组
};
},
methods: {
handleSelectionChange(selection) {
this.selectedRows = selection;
}
}
};
</script>
```
在上面的示例中,selectedRows数组存储了选中的行数据。handleSelectionChange方法会在选择状态变化时被调用,通过传入的selection参数更新selectedRows数组。
希望能帮到你!如果还有其他问题,请随时提问。