html代码:
<template>
<el-table
:data="tableData"
ref="multipleTable"
@selection-change="handleSelectionChange"
style="width: 100%">
<el-table-column
type="selection"
width="55">
</el-table-column>
<!-- 其他列 -->
</el-table>
</template>
js代码:
<script>
export default {
data() {
return {
tableData: [],
multipleSelection: []
};
},
mounted() {
this.fetchData();
},
methods: {
fetchData() {
// 模拟从服务器获取数据
this.tableData = [
// 填充数据
];
},
setDefaultSelections() {
// 假设你想默认勾选所有行
this.tableData.forEach(row => {
this.$refs.multipleTable.toggleAllSelection(row, true); //重点在这行数据
});
},
handleSelectionChange(val) {
this.multipleSelection = val;
}
}
};
</script>