el-switch 开关设置失败状态不变

页面:

页面代码:

         <el-table-column
                fixed="right"
                prop="carousel"
                label="设置展演轮播图"
                width="160px"
                v-if="rolesrow == 'ADMIN' || rolesrow == 'ADMINISTRATOR'"
            >
                <template
                    slot-scope="scope"
                    v-if="
                        scope.row.activityType == 1 &&
                            scope.row.auditStatus == 3
                    "
                >
                    <span :class="scope.row.carousel ? '' : 'free-active'"
                        >否</span
                    >
                    <el-switch
                        active-color="#67C23A"
                        inactive-color="#F56C6C"
                        :inactive-value="0"
                        :active-value="1"
                        v-model="scope.row.carousel"
                        @change="
                            handleFreeChangeYs(
                                scope.row.activityId,
                                scope.row.carousel,
                                scope.row,
                                scope.$index
                            )
                        "
                    ></el-switch>
                    <span :class="scope.row.carousel ? 'free-active' : ''"
                        >是</span
                    >
                </template>
            </el-table-column>

调用接口:

//点击开关触发的change事件并携带参数
 handleFreeChangeYs(activityId, status, row, index) {
            (接口和传参)
                .then(res => {
                    //接口调用成功改变状态
                    if (res.data.status == "success") {
                        if (status != 0) {
                            alertMessage(
                                this,
                                "【" + row.activityName + "】设置成功",
                                "success"
                            );
                        } else {
                            alertMessage(
                                this,
                                "【" + row.activityName + "】取消成功",
                                "success"
                            );
                        }
                    //接口调用失败,状态不变并提示错误
                    } else {
                        let newData = row;
                        newData.carousel = newData.carousel === 0 ? "1" : "0";
                        this.activityDatas[index] = newData;
                        alertMessage(this, res.data.message, "error");
                        return false;
                    }
                });
        },

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值