【Vue】1.ElementUI中el-switch开关切换改变值遇到的问题

需求:在切换开关的时候给个提示,确定切换开关就改变值,取消就不改变开关值

刚开始代码是这样的:

<el-table :data="tableData" border style="width: 100%">
    <el-table-column prop="ruleCode" label="规则编号" width="180"></el-table-column>
    <el-table-column prop="ruleDesc" label="规则描述"></el-table-column>
    <el-table-column prop="address" label="参数设定" width="100" align="center">
        <template slot-scope="scope" v-if="scope.row.address">
            <el-button @click="handleClickSheDing(scope.row)" type="text" size="small">设定</el-button>
        </template>
    </el-table-column>
    <el-table-column prop="uwCode" label="满足规则时的核保结论" width="180"></el-table-column>
    <el-table-column prop="reasonDesc" label="核保结论原因" width="180"></el-table-column>
    <el-table-column prop="times" label="数据获取频次" width="180"></el-table-column>
    <el-table-column prop="startDate" label="每月起始日" width="180"></el-table-column>
    <el-table-column prop="status" label="是否启用" width="100" align="center">
        <template slot-scope="scope">
            <el-switch
                v-model="scope.row.status"
                active-value="1"
                inactive-value="0"
                active-color="#13ce66"
                inactive-color="#cccccc"
                @change="changeSwitch(scope.row, $event)"
                >
            </el-switch>
        </template>
    </el-table-column>
    <el-table-column prop="address9" label="操作" width="50" align="center">
        <template slot-scope="scope">
            <el-button @click="handleClickUpdate(scope.row)" type="text" size="small">修改</el-button>
        </template>
    </el-table-column>                
</el-table>

这样遇到的问题是:切换开关,el-switch会立即改变值,不会根据传入的值改变,因为v-model是双向绑定的

解决办法:把v-model换成:value

<el-table :data="tableData" border style="width: 100%">
    <el-table-column prop="ruleCode" label="规则编号" width="180"></el-table-column>
    <el-table-column prop="ruleDesc" label="规则描述"></el-table-column>
    <el-table-column prop="address" label="参数设定" width="100" align="center">
        <template slot-scope="scope" v-if="scope.row.address">
            <el-button @click="handleClickSheDing(scope.row)" type="text" size="small">设定</el-button>
        </template>
    </el-table-column>
    <el-table-column prop="uwCode" label="满足规则时的核保结论" width="180"></el-table-column>
    <el-table-column prop="reasonDesc" label="核保结论原因" width="180"></el-table-column>
    <el-table-column prop="times" label="数据获取频次" width="180"></el-table-column>
    <el-table-column prop="startDate" label="每月起始日" width="180"></el-table-column>
    <el-table-column prop="status" label="是否启用" width="100" align="center">
        <template slot-scope="scope">
            <el-switch
                :value="scope.row.status"
                active-value="1"
                inactive-value="0"
                active-color="#13ce66"
                inactive-color="#cccccc"
                @change="changeSwitch(scope.row, $event)"
                >
            </el-switch>
        </template>
    </el-table-column>
    <el-table-column prop="address9" label="操作" width="50" align="center">
        <template slot-scope="scope">
            <el-button @click="handleClickUpdate(scope.row)" type="text" size="small">修改</el-button>
        </template>
    </el-table-column>                
</el-table>
// 开关切换
changeSwitch(row, val){
    console.log(row, '=========row switch开关===========');
    console.log(val, '=========val switch开关===========');
    this.$confirm('是否要继续切换开关?','提示',{
        confirmButtonText:'确定',
        cancelButtonText:'取消',
        type:'warning'
    }).then(() => {
        // this.submitRuleBaseSwitch(row, val); 调用接口修改数据
    }).catch(() => {
        this.$message({
            type:'info',
            message:'已取消!'
        })
    })
},

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值