【发布时间】:2019-10-22 17:20:21
【问题描述】:
我正在使用 bootstrap-vue 的模式来打开/关闭我的应用程序上的项目。
有一些事情可能会出错,例如其他人已经在后台对该项目执行了冲突操作。因此,我想阻止模式关闭,将按钮替换为加载旋转,并在 axios 调用失败时显示一些验证消息。
我有微调器、验证消息等在其他地方工作,所以我不需要帮助,但是我正在努力寻找一种在使用 msgBox 时访问 bvModalEvt 的方法,以调用 .preventDefault() on,根据文档 (https://bootstrap-vue.js.org/docs/components/modal/#prevent-closing)。
我已经在 promise 中的 this 关键字上尝试过(例如 this.preventDefault() 和其他一些东西,例如 this.$bvModal.bvModalEvt (我没想到这会起作用,但我越来越绝望!))。当在下面我的代码中的占位符处调用时,所有这些都会导致 msgBox catch 块被触发,并且模式无论如何都会关闭。
这是我的方法的基本内容:
openClose: function() {
var self = this;
this.$bvModal.msgBoxConfirm('Are you sure you want to ' + this.closeVerb + ' this item?', {
title: 'Confirmation',
size: 'md',
cancelVariant: 'gray',
okTitle: 'Confirm',
cancelTitle: 'Dismiss',
hideHeaderClose: false,
centered: true
})
.then(function(value){
// Prevent closing here
if (value === true) {
axios.post(postUrl, {
'action': self.closeVerb,
})
.then(function(response) {
// Handle here.
})
.catch(error => {
// Catch validation errors here.
})
}
})
.catch(error => {
})
}
非常感谢任何帮助!
【问题讨论】:
标签: javascript vue.js vuejs2 bootstrap-vue