ant-design-vue/components/modal/demo/confirm-promise.md

37 lines
945 B
Markdown
Raw Normal View History

2018-03-07 13:36:15 +00:00
<cn>
2018-12-15 13:50:43 +00:00
#### 确认对话框(promise)
2018-03-07 13:36:15 +00:00
使用 `confirm()` 可以快捷地弹出确认框。onCancel/onOk 返回 promise 可以延迟关闭
</cn>
<us>
2018-12-15 13:50:43 +00:00
#### Confirmation modal dialog use promise
2018-03-07 13:36:15 +00:00
To use `confirm()` to popup confirmation modal dialog. Let onCancel/onOk function return a promise object to
delay closing the dialog.
</us>
2019-10-09 10:32:23 +00:00
```tpl
2018-03-07 13:36:15 +00:00
<template>
<a-button @click="showConfirm">
Confirm
</a-button>
</template>
<script>
2019-09-28 12:45:07 +00:00
export default {
methods: {
showConfirm() {
this.$confirm({
title: 'Do you want to delete these items?',
content: 'When clicked the OK button, this dialog will be closed after 1 second',
onOk() {
return new Promise((resolve, reject) => {
setTimeout(Math.random() > 0.5 ? resolve : reject, 1000);
}).catch(() => console.log('Oops errors!'));
},
onCancel() {},
});
},
2018-03-07 13:36:15 +00:00
},
2019-09-28 12:45:07 +00:00
};
2018-03-07 13:36:15 +00:00
</script>
```