【发布时间】:2020-03-09 07:37:21
【问题描述】:
我有一个小沙箱here,有两个组件。对象列表(例如“组”)和确认模式。单击删除按钮时会触发模式。 (这个沙箱是从another post 中提取的,我在其中询问了将模态结果发送到父组件GroupList 的不同方式。
这是模态组件:
<template>
<b-modal
id="modalConfirmation"
title="Confirmation"
ok-variant="danger"
@cancel="resolvePromise(false)"
@ok="resolvePromise(true)"
@close="resolvePromise(false)"
>Are you sure you want to delete this row ?</b-modal>
</template>
<script>
export default {
name: "ModalConfirmation",
data() {
return {
group: null,
resolvePromise: null,
rejectPromise: null
};
},
methods: {
show(group) {
return new Promise((resolve, reject) => {
this.group = group;
this.$bvModal.show("modalConfirmation");
this.resolvePromise = resolve;
this.rejectPromise = reject;
});
}
}
};
</script>
对我来说最好的解决方案是这个。但是,虽然我了解 JavaScript 承诺的原理,但我无法弄清楚它在这种情况下是如何工作的。它运行良好,但我不喜欢使用我不理解的代码。
在ModalConfirmation 中,对于b-modal 标签,这些是设置模态结果的事件。但是 vuejs / bootstrap-vue 是如何做到和 promise 匹配的呢?
@ok="resolvePromise(true)"
@cancel="resolvePromise(false)"
@close="resolvePromise(false)"
因为在显示模式时调用了 promise 构造函数,仅此而已...
此外,如果我对此发表评论
resolvePromise: null,
rejectPromise: null
在模态组件中,它仍然有效。有人可以解释一下这种情况下的承诺解决流程吗?
【问题讨论】:
标签: javascript vue.js promise bootstrap-vue