el-switch 开关二次确认

<el-table-column label="AAA" align="center">
   <template slot-scope="scope">
     <el-switch
       v-model="scope.row.isRecommendTwo"
       active-color="#52C4CD"
       @change="handelUpdate(scope.$index, scope.row)"
       inactive-color="#DCDFE6"
       :active-value="true"
       :inactive-value="false"
     ></el-switch>
   </template>
 </el-table-column>
methods: {
	handelUpdate(index,row){
    // :active-value得为true
    // :inactive-value得为false
    let flag = row.isRecommendTwo //保存点击之后v-modeld的值(true,false)

    row.isRecommendTwo = !row.isRecommendTwo //保持switch点击前的状态

    this.$confirm('是否确认此操作?', '提示', {
       confirmButtonText: '确定',
       cancelButtonText: '取消',
       type: 'warning'
     }).then(() => {
       if(flag){
         row.isRecommendTwo = true
         // 逻辑处理
         this.$message.success('打开成功!')
       }else{
         row.isRecommendTwo = false
         // 逻辑处理
         this.$message.success('关闭成功!')
       }
     }).catch(() => {
      this.$message.info('取消操作!')
     });
 },

封装组件到****.js文件之后的

function Switchs(_this,row,value){
    console.log("switch开关 点击按钮后,弹窗确认再改变开关状态",row)
    return new Promise((resolve,rejects) => {
        let flag = row[value] //保存点击之后v-modeld的值(true,false)
     
        row[value] = !row[value] //保持switch点击前的状态
     
        _this.$confirm('是否确认此操作?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
        }).then(() => {
            if(flag){
                row[value] = true
                _this.$message.success('打开成功!')
                resolve(true)
            }else{
                row[value] = false
                _this.$message.success('关闭成功!')
                resolve(false)
            }
        }).catch(() => {
            _this.$message.info('取消操作!')
        });
    })
}
 
export default{
  Switchs
}

封装之后使用

improt loot from 'loot.js文件路径'
 
loot.Switchs(this,row,'isRecommendTwo').then(flag=>{
    if(flag){
      console.log('true')
    }else{
      console.log('false')
    }
})
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值