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

47 lines
1.2 KiB
Markdown
Raw Normal View History

2019-04-17 02:21:28 +00:00
<cn>
#### 销毁确认对话框
使用 `Modal.destroyAll()` 可以销毁弹出的确认窗。通常用于路由监听当中,处理路由前进、后退不能销毁确认对话框的问题。
</cn>
<us>
#### destroy confirmation modal dialog
`Modal.destroyAll()` could destroy all confirmation modal dialogs. Usually, you can use it in router change event to destroy confirm modal dialog automatically
</us>
2019-10-09 10:32:23 +00:00
```tpl
2019-04-17 02:21:28 +00:00
<template>
<a-button @click="showConfirm">
Confirm
</a-button>
</template>
<script>
2019-09-28 12:45:07 +00:00
import Button from '../../button';
export default {
methods: {
showConfirm() {
const self = this;
for (let i = 0; i < 3; i += 1) {
setTimeout(() => {
this.$confirm({
content: 'destroy all',
onOk() {
return new Promise((resolve, reject) => {
setTimeout(Math.random() > 0.5 ? resolve : reject, 1000);
}).catch(() => console.log('Oops errors!'));
},
cancelText: 'Click to destroy all',
onCancel() {
self.destroyAll();
},
});
}, i * 500);
}
},
destroyAll() {
this.$destroyAll();
},
2019-04-17 02:21:28 +00:00
},
2019-09-28 12:45:07 +00:00
};
2019-04-17 02:21:28 +00:00
</script>
```