this.$modal.confirm的使用方法

目录

问题

原因:


问题

前端画面上有这么一个功能,添加用户的时候,当企业信息没有选择的时候,需要弹出来一个提示,是否不填写企业信息直接就行用户信息的添加,是的场合,直接添加该用户,否的场合,取消添加操作,可以继续设置用户的信息。代码如下:

           else {
            if (this.form.sasBasicId == undefined || this.form.sasBasicId == "") {
              this.$modal.confirm("确定不用填写申报企业吗").then(
                addUser(this.form);
              ).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });

按照上面的方法,实现的效果是,无论选择是还是否都会走addUser的方法,都会将这条数据添加到数据库中


原因:

正确的写法如下:

           else {
            if (this.form.sasBasicId == undefined || this.form.sasBasicId == "") {
              this.$modal.confirm("确定不用填写申报企业吗").then(()=>{
                return addUser(this.form);
              }).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              }).catch(() => {
              });

 confirm后的then中的内容变了,需要return这个方法,具体的原因我还在调查中,这里先记录一下。

你可能感兴趣的:(前端页面,javascript,开发语言)