- Ant Design of Vue
- Getting Started
- Use in vue-cli
- Customize Theme
- Change Log
- Internationalization
- Components(51)
- General
- Layout
- Navigation
- Data Entry
- Data Display
- Feedback
- Other
Popconfirm
A simple and compact confirmation dialog of an action.
When To Use
A simple and compact dialog used for asking for user confirmation.
The difference with the ‘confirm’ modal dialog is that it’s more lightweight than the static popped full-screen confirm modal.
Examples
Basic #
The basic example.
<template>
<a-popconfirm title="Are you sure delete this task?" @confirm="confirm" @cancel="cancel" okText="Yes" cancelText="No">
<a href="#">Delete</a>
</a-popconfirm>
</template>
<script>
export default {
methods: {
confirm (e) {
console.log(e)
this.$message.success('Click on Yes')
},
cancel (e) {
console.log(e)
this.$message.error('Click on No')
},
},
}
</script>
Locale text #
Set okText
and cancelText
props to customise the button's labels.
<template>
<a-popconfirm title="Are you sure?" okText="Yes" cancelText="No">
<a href="#">Delete</a>
</a-popconfirm>
</template>
Placement #
There are 12 placement
options available. Use arrowPointAtCenter
if you want arrow point at the center of target.
<template>
<div id="components-a-popconfirm-demo-placement">
<div :style="{ marginLeft: `${buttonWidth}px`, whiteSpace: 'nowrap' }">
<a-popconfirm placement="topLeft" okText="Yes" cancelText="No" @confirm="confirm">
<template slot="title">
<p>Are you sure delete this task?</p>
<p>Are you sure delete this task?</p>
</template>
<a-button>TL</a-button>
</a-popconfirm>
<a-popconfirm placement="top" okText="Yes" cancelText="No" @confirm="confirm">
<template slot="title">
<p>Are you sure delete this task?</p>
<p>Are you sure delete this task?</p>
</template>
<a-button>Top</a-button>
</a-popconfirm>
<a-popconfirm placement="topRight" okText="Yes" cancelText="No" @confirm="confirm">
<template slot="title">
<p>Are you sure delete this task?</p>
<p>Are you sure delete this task?</p>
</template>
<a-button>TR</a-button>
</a-popconfirm>
</div>
<div :style="{ width: `${buttonWidth}px`, float: 'left' }">
<a-popconfirm placement="leftTop" okText="Yes" cancelText="No" @confirm="confirm">
<template slot="title">
<p>Are you sure delete this task?</p>
<p>Are you sure delete this task?</p>
</template>
<a-button>LT</a-button>
</a-popconfirm>
<a-popconfirm placement="left" okText="Yes" cancelText="No" @confirm="confirm">
<template slot="title">
<p>Are you sure delete this task?</p>
<p>Are you sure delete this task?</p>
</template>
<a-button>Left</a-button>
</a-popconfirm>
<a-popconfirm placement="leftBottom" okText="Yes" cancelText="No" @confirm="confirm">
<template slot="title">
<p>Are you sure delete this task?</p>
<p>Are you sure delete this task?</p>
</template>
<a-button>LB</a-button>
</a-popconfirm>
</div>
<div :style="{ width: `${buttonWidth}px`, marginLeft: `${buttonWidth * 4 + 24 }px`}">
<a-popconfirm placement="rightTop" okText="Yes" cancelText="No" @confirm="confirm">
<template slot="title">
<p>Are you sure delete this task?</p>
<p>Are you sure delete this task?</p>
</template>
<a-button>RT</a-button>
</a-popconfirm>
<a-popconfirm placement="right" okText="Yes" cancelText="No" @confirm="confirm">
<template slot="title">
<p>Are you sure delete this task?</p>
<p>Are you sure delete this task?</p>
</template>
<a-button>Right</a-button>
</a-popconfirm>
<a-popconfirm placement="rightBottom" okText="Yes" cancelText="No" @confirm="confirm">
<template slot="title">
<p>Are you sure delete this task?</p>
<p>Are you sure delete this task?</p>
</template>
<a-button>RB</a-button>
</a-popconfirm>
</div>
<div :style="{ marginLeft: `${buttonWidth}px`, clear: 'both', whiteSpace: 'nowrap' }">
<a-popconfirm placement="bottomLeft" okText="Yes" cancelText="No" @confirm="confirm">
<template slot="title">
<p>Are you sure delete this task?</p>
<p>Are you sure delete this task?</p>
</template>
<a-button>BL</a-button>
</a-popconfirm>
<a-popconfirm placement="bottom" okText="Yes" cancelText="No" @confirm="confirm">
<template slot="title">
<p>Are you sure delete this task?</p>
<p>Are you sure delete this task?</p>
</template>
<a-button>Bottom</a-button>
</a-popconfirm>
<a-popconfirm placement="bottomRight" okText="Yes" cancelText="No" @confirm="confirm">
<template slot="title">
<p>Are you sure delete this task?</p>
<p>Are you sure delete this task?</p>
</template>
<a-button>BR</a-button>
</a-popconfirm>
</div>
</div>
</template>
<script>
import { message } from 'ui-vue-antd'
export default {
data () {
return {
buttonWidth: 70,
}
},
methods: {
confirm () {
message.info('Click on Yes.')
},
},
}
</script>
<style scoped>
#components-a-popconfirm-demo-placement .ant-btn {
width: 70px;
text-align: center;
padding: 0;
margin-right: 8px;
margin-bottom: 8px;
}
</style>
Conditional trigger #
Make it pop up under some conditions.
<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>
<script>
import { message } from 'ui-vue-antd'
export default {
data () {
return {
visible: false,
condition: true,
}
},
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
}
},
},
}
</script>
API #
Param | Description | Type | Default value |
---|---|---|---|
cancelText | text of the Cancel button | string|slot | Cancel |
okText | text of the Confirm button | string|slot | Confirm |
okType | Button type of the Confirm button | string | primary |
title | title of the confirmation box | string|slot | - |
events #
Events Name | Description | Arguments |
---|---|---|
cancel | callback of cancel | function(e) |
confirm | callback of confirmation | function(e) |
visibleChange | Callback executed when visibility of the tooltip card is changed | function(visible) |
Consult Tooltip's documentation to find more APIs.
Note #
Please ensure that the child node of Popconfirm
accepts mouseenter
, mouseleave
, focus
, click
events.