一、单选实现:
1、table 部分
<el-table
:data="tableData"
@row-click = "showRow"
>
2、column 部分
<el-table-column label="选择" width="50" align="center">
<template scope="scope">
<el-radio class="radio" v-model="radio" :label="scope.$index"> </el-radio>
</template>
</el-table-column>
3、data 部分
data:{
tableData: [],
multipleSelection: [],
radio: '',
selected:{}
},
4、method 部分
showRow(row){
//赋值给radio
this.radio = this.tableData.indexOf(row);
this.selected=row;
},
===============================================================================================
之后在其他方法内就可以拿着 this.selected 去用了。
注意:实现之后单选框并不会自动居中,需要自己调一下样式。
二、多选实现
1、table 部分
<el-table
:data="tableData"
ref="multipleTable"
@selection-change="handleSelectionChange"
>
2、column 部分
<el-table-column
type="selection"
align="center"
width="55">
</el-table-column>
3、data 部分
data:{
tableData: [],
multipleSelection: []
},
4、method 部分
handleSelectionChange(val) {
var thispage = this;
thispage.multipleSelection = val;
},
===============================================================================
点击列中的按钮 实现该行被选中
1、column 部分
<el-table-column label="操作" width="360" align="center" >
<template slot-scope="scope">
<el-button type="danger" plain
size="mini"
@click="delOne(scope.$index, scope.row)">删除
</el-button>
</template>
</el-table-column>
2、method 部分
delOne(index, row){
this.$refs.multipleTable.toggleRowSelection(row);
}