vue点击el-switch开关,弹出提示框(点击事件js触发弹框)

 html

          <el-table-column
            prop="state"
            label="是否可见"
            min-width="180"
            align="center"
          >
            <template slot-scope="{ row }">
              <div>
                <el-switch
                  @click.native="bulletinSwitch(row.id, row.state)"
                  v-model="row.state"
                  active-color="#FF570F"
                  inactive-color="#4a4a4a"
                  :active-value="1"
                  :inactive-value="2"
                  disabled
                >
                  <!-- @change="bulletinSwitch(row.id, row.state)" -->
                </el-switch>
              </div>
            </template>
          </el-table-column>

 


methods

    // 官方公告的是否可见 的switch事件
    async bulletinSwitch(itemId, itemState) {
      console.log(itemId, itemState, "官方公告的id和状态-----");

      this.$confirm(
        `${itemState == 2 ? "启用" : "停用"}后,官方公告 将会 ${
          itemState == 2 ? "发布" : "无法撤回"
        },请选择`,
        `确定${itemState == 2 ? "启用" : "停用"}该官方公告吗?`,
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
          center: true,
        }
      ).then(async () => {
        itemState = itemState == 2 ? 1 : 2;
        const res = await getUpdateNoticeInfo({
          userId: "1",
          id: "" + itemId,
          state: itemState,
        });
        if (res.status === 200) {
          console.log(res, "111111");
          this.$message.success("状态改变成功");
          this.getNoticeList();
        } else {
          this.$message.error("操作有误,请重新操作。");
        }
      });
    },

 


 原始开关的写法

    // 原始的写法,没有弹窗的
    // bulletinSwitch(itemId, itemState) {
    //   console.log(itemId, itemState, "官方公告的id和状态-----");
    //   // 修改官方公告信息-可不可见-1可见2不可见
    //   getUpdateNoticeInfo({
    //     userId: "1",
    //     id: "" + itemId,
    //     state: itemState,
    //   }).then((res) => {
    //     // console.log(res, "修改是否可见的返回值-----");
    //     if (res.status === 200) {
    //       this.$message.success("修改是否可见成功");
    //       this.getNoticeList();
    //     } else {
    //       this.$message.error("操作有误,请重新操作。");
    //     }
    //   });
    // },

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值