<el-table
ref="multipleTable"
:data="tableData"
:header-cell-style="{background:'#F8F8F9'}"
style="width: 100%;margin-top: 20px">
<el-table-column label="選擇" align="center" width="65">
<template scope="scope">
<el-radio :label="scope.$index" v-model="radio"
@change.native="getCurrentRow(scope.row)"></el-radio>
</template>
</el-table-column>
<el-table-column align="center" label="編號" width="160" prop="studentCode"></el-table-column>
<el-table-column align="center" prop="name" label="姓名" width="120"></el-table-column>
<el-table-column align="center" prop="phone" label="賬號"></el-table-column>
</el-table>
在使用el-radio標簽的時候,需要綁定label的值,這里label我綁定的是index,有時候在單選位置是不需要將label的值顯示出來,這個時候只需要在el-radio標簽里面加上'  ;'即可。
<el-radio :label="scope.$index"
v-model="radio"
@change.native="getCurrentRow(scope.row)"> </el-radio>
js代碼實現如下:
data: {
return() {
templateSelection: {},
radio: '',
tableData: []
}
}
methods: {
getCurrentRow(row){
// 獲取選中數據 row表示選中這一行的數據,可以從里面提取所需要的值
this.templateSelection = row
}
}