问题
最近写项目发现,使用elementUI的MessageBox的prompt 异步提交数据时,存在点了确定弹窗关闭并且不再执行then下面的指令,自然也就没办法继续执行。
经过一番测试,解决办法为:使用callback方法来代替Promise,示例代码如下
this.$prompt('请输入密码', '管理员登录', { confirmButtonText: '确定', inputPlaceholder: '密码必须包含大小写字母和数字的组合', cancelButtonText: '取消', inputPattern: /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,16}$/, inputErrorMessage: '密码格式不正确', callback: function (action, instance) { if (action === 'confirm') { self.$axios({ url: self.$serverUrl + '/index/Server/RconLogin', method: 'POST', data: {你要提交的数据} }).then(function (res) { if (res.data.status === 'success') { self.$message({ type: 'success', message: '成功进入管理员模式!' }) self.ServerInfoDialog.adminMode = true } }).catch(function (error) { self.$message({ type: 'danger', message: error.response.data }) }) } } })
这样就可以在窗口关闭之后继续执行回调内的代码了。请注意 instance.inputValue 的值就是prompt内输入的信息
Comments 2 条评论
作者,你好!我是腾讯云+社区的小编,关注了您分享的技术文章,觉得很棒,我们诚挚邀请您加入云+社区,与我们众多的社区作者一起为开发者分享技术干货。这个是我们云+社区【腾讯云自媒体分享计划】入驻流程和权益介绍的地址:https://cloud.tencent.com/developer/support-plan 如果您愿意加入或者想了解更多的信息请联系我~微信:techou002,我们对您的加入充满期待。
Your style is unique compared to other folks I have read stuff from.
I appreciate you for posting when you have the opportunity, Guess I
will just bookmark this blog.