el-dialog 的属性
element-ui dialog对话框组件的具体使用
element-ui dialog对话框组件的具体使用
对话框的格式:
<el-dialog>
</el-dialog>
dialog的属性
dialog的插槽
插槽比较常用
dialog的事件
常用属性与事件的说明
属性
:visible.sync="dialogVisible" 是否显示对话框,.sync修饰符实时更新数据
参数为boolean类型,为true时显示对话框,为false不显示对话框
:titel="title" 对话框的标题,参数为string类型
width="30%" 对话框的宽度
:append-to-body="true" 对话框自身是否插入到body元素中,(嵌套的对话框该属性必须为true,默认为false)
:before-close="function()" 关闭前的回调,会暂停对话框的关闭,是处理对话框中关闭按钮的事件
事件
@close="function()" 对话框关闭的回调,一般用于清空弹窗中的数据
实例
父组件
<template>
<div class="app-container">
<div class="the-container">
<div>
<el-button type="primary" @click="openDialog">打开对话框</el-button>
</div>
</div>
<Dialog ref="dialog" />
</div>
</template>
<script>
import Dialog from './dialog'
export default {
name: 'Index',
components: {
Dialog
},
data() {
return {
}
},
methods: {
openDialog() {
this.$refs.dialog.show()
}
}
}
</script>
<style lang="scss" scoped>
.app-container{
height: 100%;
background-color: #f1f1f1;
}
.the-container{
height: 100%;
background-color: #fff;
padding: 20px;
display: flex;
justify-content: center;
}
</style>
子组件
<template>
<el-dialog
title="提示"
:visible="dialogVisible"
width="30%"
:append-to-body="true"
@close="handleClose"
>
<span>这一个对话框测试</span>
<span slot="footer" class="dialog-footer">
<el-button @click="dialogVisible = false">取 消</el-button>
<el-button type="primary" @click="dialogVisible = false">确 定</el-button>
</span>
</el-dialog>
</template>
<script>
export default {
name: 'Dialog',
data() {
return {
dialogVisible: false
}
},
methods: {
show() {
this.dialogVisible = true
},
handleClose() {
this.dialogVisible = false
console.log('close')
}
}
}
</script>
<style scoped>
</style>
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通