ant-design-vue/components/popconfirm/demo/dynamic-trigger.md

69 lines
1.4 KiB
Markdown
Raw Normal View History

2018-03-22 08:19:02 +00:00
<cn>
#### 条件触发
2018-01-15 09:33:34 +00:00
可以判断是否需要弹出。
2018-03-22 08:19:02 +00:00
</cn>
2018-01-15 09:33:34 +00:00
2018-03-22 08:19:02 +00:00
<us>
#### Conditional trigger
Make it pop up under some conditions.
</us>
2019-10-09 10:32:23 +00:00
```tpl
2018-03-22 08:19:02 +00:00
<template>
<div>
<a-popconfirm
title="Are you sure delete this task?"
:visible="visible"
@visibleChange="handleVisibleChange"
@confirm="confirm"
@cancel="cancel"
okText="Yes"
cancelText="No"
>
<a href="#">Delete a task</a>
</a-popconfirm>
<br />
<br />
Whether directly execute<a-checkbox defaultChecked @change="changeCondition" />
</div>
</template>
2018-01-15 09:33:34 +00:00
<script>
2019-09-28 12:45:07 +00:00
import { message } from 'ant-design-vue';
2018-03-22 08:19:02 +00:00
2019-09-28 12:45:07 +00:00
export default {
data() {
return {
visible: false,
condition: true,
};
2018-01-15 09:33:34 +00:00
},
2019-09-28 12:45:07 +00:00
methods: {
changeCondition(e) {
this.condition = e.target.checked;
},
confirm() {
this.visible = false;
message.success('Next step.');
},
cancel() {
this.visible = false;
message.error('Click on cancel.');
},
handleVisibleChange(visible) {
if (!visible) {
this.visible = false;
return;
}
// Determining condition before show the popconfirm.
console.log(this.condition);
if (this.condition) {
this.confirm(); // next step
} else {
this.visible = true;
}
},
2018-01-15 09:33:34 +00:00
},
2019-09-28 12:45:07 +00:00
};
2018-01-15 09:33:34 +00:00
</script>
2018-03-22 08:19:02 +00:00
```