用element ui写一个退回弹出框
时间: 2023-07-08 21:48:54 浏览: 23
好的,以下是用 Element UI 实现退回弹出框的示例代码:
```html
<template>
<div>
<el-button type="danger" @click="showDialog">退回</el-button>
<el-dialog
title="退回原因"
:visible.sync="dialogVisible"
:before-close="handleClose"
>
<el-form ref="form" :model="form" label-width="80px">
<el-form-item label="退回原因" prop="reason">
<el-input type="textarea" v-model="form.reason"></el-input>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="dialogVisible = false">取消</el-button>
<el-button type="primary" @click="handleReturn">确定</el-button>
</div>
</el-dialog>
</div>
</template>
<script>
export default {
data() {
return {
dialogVisible: false,
form: {
reason: "",
},
};
},
methods: {
showDialog() {
this.dialogVisible = true;
},
handleClose(done) {
this.$confirm("确定关闭吗?")
.then(() => {
done();
})
.catch(() => {});
},
handleReturn() {
this.$emit("return", this.form.reason);
this.dialogVisible = false;
},
},
};
</script>
```
在上面的代码中,我们使用了 `el-dialog` 组件来创建退回弹出框,使用了 `el-form` 组件来创建表单,使用了 `el-input` 组件来创建多行文本框,使用了 `el-button` 组件来创建按钮,使用了 `slot` 来自定义弹出框的底部按钮。在弹出框关闭前,使用了 `before-close` 事件来弹出确认提示框,确保用户不会误操作。在点击弹出框的确定按钮后,使用了 `$emit` 方法来触发 `return` 事件,并将用户输入的退回原因作为参数传递给父组件。
相关推荐














