popconfirm的回调函数使用
<el-popconfirm
confirm-button-text="好的"
cancel-button-text="不用了"
icon="el-icon-info"
icon-color="red"
title="这是一段内容确定删除吗?"
@confirm="handleconfirm"
@cancel="handlecancel"
>
<el-button slot="reference">删除</el-button>
</el-popconfirm>
methods: {
handleconfirm() {
console.log('xiaoyee')
},
handlecancel() {
console.log('xiaoyee')
}
}
源码:这里是通过this.$emit
去触发回调
注意:版本问题,之前的版本是this.$emit('onConfirm')
,回调会使用onConfirm方法
<div class="el-popconfirm__action">
<el-button
size="mini"
:type="cancelButtonType"
@click="cancel"
>
{{ displayCancelButtonText }}
</el-button>
<el-button
size="mini"
:type="confirmButtonType"
@click="confirm"
>
{{ displayConfirmButtonText }}
</el-button>
</div>
methods: {
confirm() {
this.visible = false;
this.$emit('confirm');
},
cancel() {
this.visible = false;
this.$emit('cancel');
}
}