建议参照例子使用 v-transfer-dom 将弹窗插入 body 节点下,避免组件非 body 子节点导致的各种问题。
该组件支持以plugin形式调用:
以插件形式调用时,和template中使用不同,属性名请使用小驼峰式,比如confirmText而不是confirm-text。
import { ConfirmPlugin } from 'vux'
Vue.use(ConfirmPlugin)
// 显示
const _this = this // 需要注意 onCancel 和 onConfirm 的 this 指向
this.$vux.confirm.show({
// 组件除show外的属性
onCancel () {
console.log(this) // 非当前 vm
console.log(_this) // 当前 vm
},
onConfirm () {}
})
// 隐藏
this.$vux.confirm.hide()
// prompt形式调用
this.$vux.confirm.prompt('placeholder', {
onCancel () {}
onConfirm () {}
})
// 设置输入值
this.$vux.confirm.setInputValue('value') // 注意需要在 onShow 事件中执行
// 获取显示状态
this.$vux.confirm.isVisible() // v2.9.1 支持
API
Props
| name | type | default | description | required version |
| value | boolean | false | visibility of the component | -- |
| show-input | boolean | false | whether show input or not. If true, slot will not work | v2.5.0 |
| placeholder | string | placeholder of prompt, valid when show-input is true | v2.5.0 | |
| theme | string | ios | dialog's style, can be ios or android | -- |
| hide-on-blur | boolean | false | if closing dialog when clicking on mask | -- |
| title | string | dialog title | -- | |
| content | string | dialog content, can use html. Invalid when using slot | -- | |
| confirm-text | string | 确认(confirm) | text of confirm button | -- |
| cancel-text | string | 取消(cancel) | text of cancel button | -- |
| mask-transition | string | vux-fade | mask's transition | -- |
| dialog-transition | string | vux-dialog | dialog's transition | -- |
| close-on-confirm | boolean | true | whether close automatically when confirm button is clicked | v2.5.0 |
| input-attrs | object | input attributes | v2.5.7 | |
| mask-z-index | number string | 1000 | zIndex of mask | v2.6.4 |
| show-cancel-button | boolean | true | if show cancel button | v2.9.2 |
| show-confirm-button | boolean | true | if show confirm button | v2.9.2 |
Events
| name | params | description | required version |
| @on-cancel | -- | triggers when the cancel button is clicked | -- |
| @on-confirm | (value) | triggers when the confirm button is clicked | -- |
| @on-show | -- | triggers when the dialog shows | -- |
| @on-hide | -- | triggers when the dialog hides | -- |
Slots
| name | description | required version |
| default | body content of the dialog | -- |
Functions
| name | params | description | required version |
| setInputValue | (value) | set input value when show-input is true | v2.5.5 |
Contributors
Contributors
Total commits quantity: 50,Total contributors quantity: 8
airylandunclayzhangzicaoSapphireKwanQiongrong JiangFisher光君Changelog
Releases
- v2.9.2 [feature] Support prop: showCancelButton showConfirmButton #2795
- v2.9.1 [feature] add isVisible function for ConfirmPlugin #2704
- v2.9.0 [fix] fix inputAttrs issue with no-default-value #2618
- v2.9.0 [fix] fix focus auto-blur issue #2610
- v2.8.0 [fix] fix hard to move cursor
- v2.7.3 [fix] fix hard to get focus on input(thanks to @Sapphire2k)
- v2.6.5 [enhance] fix click events trigger twice when clicking fast #2048
- v2.6.4 [feature] support prop:mask-z-index
- v2.5.8 [feature] Support method:setInputValue for plugin #1846
- v2.5.7 [feature] Support prop:input-attrs #1799
- v2.5.5 [feature] Add method:setInputValue #1746
- v2.5.0 [feature] Support prop:close-on-confirm
- v2.5.0 [feature] Support prop:show-input
- v2.1.1-rc.11 [fix] Fix plugin value and event watchers
- v2.1.1-rc.11 [fix] Reset prop data when used as plugin