用element怎么写一个弹框
时间: 2023-11-26 10:04:48 浏览: 74
vue项目中仿element-ui弹框效果的实例代码
以下是一个基于 Element UI 的弹框组件的示例代码:
```html
<template>
<el-dialog
:visible.sync="dialogVisible"
:title="dialogTitle"
:width="dialogWidth"
@close="handleClose"
>
<span>{{ dialogContent }}</span>
<div slot="footer">
<el-button @click="dialogVisible = false">取消</el-button>
<el-button type="primary" @click="handleConfirm">确定</el-button>
</div>
</el-dialog>
</template>
<script>
export default {
data() {
return {
dialogVisible: false,
dialogTitle: '',
dialogWidth: '',
dialogContent: '',
};
},
methods: {
openDialog(title, width, content) {
this.dialogTitle = title;
this.dialogWidth = width;
this.dialogContent = content;
this.dialogVisible = true;
},
handleClose() {
this.dialogVisible = false;
},
handleConfirm() {
// 处理确认操作
this.dialogVisible = false;
},
},
};
</script>
```
使用时,可以在组件中调用 `openDialog` 方法来打开弹框,例如:
```html
<template>
<div>
<el-button @click="openDialog">打开弹框</el-button>
</div>
</template>
<script>
import Dialog from './Dialog';
export default {
components: {
Dialog,
},
methods: {
openDialog() {
this.$refs.dialog.openDialog('弹框标题', '50%', '弹框内容');
},
},
};
</script>
```
阅读全文