我想使用 bootstrap vue modal 组件 在 vuejs 应用程序中实现此功能:
当用户点击页面 UI 上的删除按钮时:
它显示了主体中带有动态内容的模态:“您确定要删除客户:customer_name_here”
如果用户点击“取消”按钮:模态消失。
如果用户点击“确定”按钮:
它将模态正文内容更改为:’Deleting customer ‘customer_name_here’ …,禁用取消和确定按钮,并调用 API 来删除客户。
当从 API 收到成功响应时:
- 它将模态正文内容更改为:“成功删除客户‘customer_name_here’
- 仅在模态页脚中显示确定按钮,如果单击模态,该按钮就会消失。
这是到目前为止的代码:
<b-button v-b-modal.modal1 variant="danger">Delete</b-button>
<b-modal id="modal1" title="Delete Customer"
@ok="deleteCustomer" centered no-close-on-backdrop -close-on-esc ref="modal">
<p class="my-4">Are you sure, you want to delete customer:</p>
<p>{{customer.name}}</p>
</b-modal>
VueJS 代码:
deleteCustomer(evt) {
evt.preventDefault()
this.$refs.modal.hide()
CustomerApi.deleteCustomer(this.customer.id).then(response => {
// successful response
})
原文由 ace 发布,翻译遵循 CC BY-SA 4.0 许可协议
如果我没理解错的话,你想显示基于不同状态组合的模态内容。
根据您的描述,应该有两种状态:
deletingState:表示是否开始删除
loadingState:表示是否正在等待服务器响应
查看 Bootstrap Vue Modal Guide ,然后搜索 keyword= Disabling built-in buttons ,你会看到我们可以使用
cancel-disabled
和ok-disabled
道具来控制默认 取消 和 确定 按钮的禁用状态(或者你可以使用 slot= modal-footer ,或 modal-ok , modal-cancel 。)。您可以使用的其他道具:
ok-only
,cancel-only
,busy
。最后绑定
v-if
和 props 与状态组合以显示内容。像下面的演示: