【发布时间】:2020-11-18 16:24:30
【问题描述】:
Buefy Modal 的默认行为是在单击外部(或按 ESC)时关闭。 但是,在处理长输入时,这种行为可能是有害的,因为错误的点击可能会使用户失去所有工作。
如何防止 Buefy Modal 在外部单击时关闭(在 VueJS / NustJS 中)?
在下面的示例中,我创建了一个包含模式的自定义组件(卡片模式:https://buefy.org/documentation/modal)。然后在父页面中,我使用以下功能打开模式:
methods: {
createNew(type) {
this.$store.commit('SET_MODAL_TYPE', type)
this.$buefy.modal.open({
parent: this,
component: createNewModal,
hasModalCard: true,
customClass: 'custom-class custom-class-2',
trapFocus: true,
})
},
},
更新:
根据接受的答案,解决方案非常简单,只需在调用模式时添加canCancel: ['x']:
methods: {
createNew(type) {
this.$store.commit('SET_MODAL_TYPE', type)
this.$buefy.modal.open({
parent: this,
component: createNewModal,
hasModalCard: true,
trapFocus: true,
canCancel: ['x'],
})
},
},
【问题讨论】:
标签: vue.js modal-dialog bulma buefy nuxtjs