element UI中table组件实现单选操作

项目中使用element UI的table组件实现选择短信模板的功能,需要用到单选按钮,实现效果:

 element UI中table组件实现单选操作_第1张图片

 

代码:

 

<el-table :data="shortTemplateData" border style="width: 100%" ref="multipleTable">
    <el-table-column label="" width="65">
        <template scope="scope">
            <el-radio :label="scope.row.messageTemplateId" v-model="templateRadio" @change.native="getTemplateRow(scope.$index,scope.row)"> el-radio>
        template>
    el-table-column>
    <el-table-column prop="messageTemplateBody" label="模板内容" min-width="500">
    el-table-column>
el-table>
<div class="pagination">
    <el-pagination
        @current-change ="handleCurrentChange"
        layout="total,prev, pager, next"
        :total="pageTotal" :page-size="pageSize">
    el-pagination>
div>

其中: 

element UI中table组件实现单选操作_第2张图片

因为label的原因,会在radio后面有短信模板ID出现,所以添加了‘  ’以空格显示。

获取数据的方法:

getTemplateRow(index,row){                                 //获取选中数据
    this.templateSelection = row;
},

 

因为是通用组件,所以获取了整个row中的数据,需要时在页面中单独获取。

你可能感兴趣的:(工作总结)