ant-design-vue/components/popconfirm/demo/promise.vue

48 lines
1022 B
Vue
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<docs>
---
order: 7
version: 3.0
title:
zh-CN: 基于 Promise 的异步关闭 (3.0+)
en-US: Asynchronously close on Promise (3.0+)
---
## zh-CN
点击确定后异步关闭 Popconfirm例如提交表单
## en-US
Asynchronously close a popconfirm when the OK button is pressed. For example, you can use this pattern when you submit a form.
</docs>
<template>
<a-popconfirm title="Title" @confirm="confirm" @cancel="cancel">
<a-button type="primary">Open Popconfirm with Promise</a-button>
</a-popconfirm>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import { message } from 'ant-design-vue';
export default defineComponent({
setup() {
const confirm = (e: MouseEvent) => {
console.log(e);
return new Promise(resolve => {
setTimeout(() => resolve(true), 3000);
});
};
const cancel = (e: MouseEvent) => {
console.log(e);
message.error('Click on No');
};
return {
confirm,
cancel,
};
},
});
</script>