当前位置:   article > 正文

Element UI中table表格中使用Switch 开关及调接口_elementui el-table列表中加入switch 开关

elementui el-table列表中加入switch 开关

效果图:

1.表格代码,给el-waitch加上change事件

  1. <el-table-column
  2. prop="status"
  3. label="状态"
  4. align="center"
  5. width="150">
  6. <template slot-scope="scoped">
  7. <el-switch
  8. active-color="#13ce66"
  9. inactive-color="#ff4949"
  10. v-model="scoped.row.status"
  11. @change="changeStatus($event,scoped.row,scoped.$index)">
  12. </el-switch>
  13. </template>
  14. </el-table-column>

 注意:使用时在 v-model=“scope.row.字段”可以把后端返回的开关数据展示在表格中 

2.调接口。

  1. changeStatus(e,row,index){
  2. console.log(e,row,index) //e返回状态,row当前行数据,index下标
  3. let pramas={
  4. userId:Number(this.userInfo.id),//操作人id
  5. status:row.status,//启用状态:false-未启用,true-启用
  6. worksClass:Number(row.worksClass),// 作品类别
  7. worksClassDonationRuleId:Number(row.id) 当前启用/禁用的记录id
  8. }
  9. this.$api.operateMgmt.donationruleenable(pramas)
  10. .then(res =>{
  11. if(res.code == 200){
  12. this.$message({
  13. message: '开启成功,请刷新页面',
  14. type: 'success'
  15. });
  16. }else{
  17. this.$message.error('当前记录是唯一启用的规则,不可禁用');
  18. }
  19. })
  20. },

重点:方法名(e,row,index) //e返回状态true或false,row当前行数据,index下标

打印出的数据

 

 通过以上两步就可以实现效果图。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/代码探险家/article/detail/740153
推荐阅读
相关标签
  

闽ICP备14008679号