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

69 lines
1.3 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>
```html
<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>
2018-05-15 01:52:44 +00:00
import { message } from 'vue-antd-ui'
2018-03-22 08:19:02 +00:00
2018-01-15 09:33:34 +00:00
export default {
data () {
return {
visible: false,
condition: true,
}
},
methods: {
changeCondition (e) {
this.condition = e.target.checked
},
confirm () {
this.visible = false
2018-03-22 08:19:02 +00:00
message.success('Next step.')
2018-01-15 09:33:34 +00:00
},
cancel () {
this.visible = false
2018-03-22 08:19:02 +00:00
message.error('Click on cancel.')
2018-01-15 09:33:34 +00:00
},
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
}
},
},
}
</script>
2018-03-22 08:19:02 +00:00
```