el-switch使用

效果图:

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

 <el-table-column
            prop="status"
            label="状态"
            align="center"
            width="150">
      <template slot-scope="scoped">
         <el-switch
           active-color="#13ce66"
           inactive-color="#ff4949"
           v-model="scoped.row.status"
           @change="changeStatus($event,scoped.row,scoped.$index)">
        </el-switch>
      </template>
  </el-table-column>
 注意:使用时在 v-model=“scope.row.字段”可以把后端返回的开关数据展示在表格中 

2.调接口。

changeStatus(e,row,index){
  console.log(e,row,index) //e返回状态,row当前行数据,index下标
      let pramas={
        userId:Number(this.userInfo.id),//操作人id
        status:row.status,//启用状态:false-未启用,true-启用
        worksClass:Number(row.worksClass),// 作品类别
        worksClassDonationRuleId:Number(row.id) 当前启用/禁用的记录id
      }
      this.$api.operateMgmt.donationruleenable(pramas)
        .then(res =>{
          if(res.code == 200){
            this.$message({
              message: '开启成功,请刷新页面',
              type: 'success'
            });
          }else{
            this.$message.error('当前记录是唯一启用的规则,不可禁用');
          }
        })
    },
重点:方法名(e,row,index) //e返回状态true或false,row当前行数据,index下标

打印出的数据

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

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值