對 el-dialog 二次封裝成元件
阿新 • • 發佈:2021-12-20
<template> <el-dialog class="my-dialog" width="70%" :visible.sync="dialogVisible" > <div>dialog內容區域</div> <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: 'MyDialog', props: { show: { type: Boolean, default: false } }, computed: { dialogVisible: { get() { return this.show }, set(val) { this.$emit('update:show', val) } } } } </script> <style lang="less" scoped></style>
使用MyDialog元件
完結~<template> <el-button @click="showMyDialog = !showMyDialog">開啟/關閉MyDialog</el-button> <MyDialog :show.sync="showMyDialog"></MyDialog> </template> <script> data() { return { showMyDialog: false } } </script> <style lang="less" scoped></style>