elementui的表格单选选中之后可以取消的方法

先看图!!!

 注意看了!!!以下为核心代码!!!

//@click.native.stop.prevent 这句话必不可少哦,否则他会点击两次
<el-table :data="questionnaireList" border>
  <el-table-column label="选择" width="70" header-align="center" align="center">
     <template slot-scope="scope">
       <el-radio class="radio" v-model="questionnaireId" :label="scope.row.id" 
         @click.native.stop.prevent="getCurrentRow(scope.row)">&nbsp;</el-radio>
     </template>
  </el-table-column>
</el-table>

//再次点击取消单选选中状态
getCurrentRow(row) {//this.questionnaireId 为上一次存储的id与这一次比对判断是否和上次点击的一致
     if (this.questionnaireId == row.id) {
         this.questionnaireId = null
     } else {
         this.questionnaireId = row.id
     }
 }

这样elementui的表格单选选中之后可以取消的方法就解决了!!!

猜你喜欢

转载自blog.csdn.net/weixin_51338875/article/details/128819423