学无先后,达者为师

网站首页 编程语言 正文

前端写代码的时候,不满足条件程序停止执行下面的程序,并弹窗提示

作者:migexiaoliang 更新时间: 2022-08-15 编程语言

项目场景:

前端写代码的时候,有时候需要满足条件才可以执行下面的程序,不满足条件程序停止执行,并弹窗提示不满足的原因。
在这里插入图片描述


代码实现

实现代码:

      if (this.channnelConfig.user_info_change_sms == '0') {
        this.$notify({  //不满足条件,弹窗提示
          message: '修改不成功',
          type: 'warning',
        });
        return;
      }

例如在项目中的使用:

    changeStatus(target, bomb) {
      if (this.channnelConfig.user_info_change_sms == '0') {
        this.$notify({
          message: '修改不成功',
          type: 'warning',
        });
        return;
      }
      //如果上面条件不满足,下面的接口调用程序不会继续执行
      sendMessageReq
        .editSysConfig({
          [target]: bomb,
        })
        .then(res => {
          if () {
           .
           .
           .
            this.$notify({
              title: '成功',
              message: res.data.msg || '修改配置成功!',
              type: 'success',
            });
          }
        })
        .catch(err => {
          console.log(err);
          // 如果失败,刷新回原来的数据
          .
          .
          .
        });
    },

原文链接:https://blog.csdn.net/migexiaoliang/article/details/124277070

栏目分类
最近更新