vue3 、Element Plus新增公共组件或共用组件----Dialog 对话框组件

此环境在vue3下,用的是Element Plus组件库。

Dialog 对话框组件样式:

在这里插入图片描述

文件对应位置:

在这里插入图片描述

子组件代码:

<template>
    <div>
        <el-dialog :title="title" :model-value="dialogVisible" :append-to-body="true" :close-on-click-modal="clickClose"
            :width="width" :before-close="handleClose">
            <el-tabs type="border-card" style="margin-top:-20px">
                <el-tab-pane :label="subTitle ? subTitle : title">
                    <slot></slot>
                </el-tab-pane>
            </el-tabs>
        </el-dialog>
    </div>
</template>

<script lang='ts'>
import { defineComponent, reactive, toRefs, SetupContext } from 'vue'
interface Data {
    name: string;
}
export default defineComponent({
    name: '',
    props: {
        title: { //弹框标题,必传
            type: String,
            default: {}
        },
        dialogVisible: { //控制弹框显示隐藏,必传
            type: Boolean,
            default: {}
        },
        clickClose: { //点击弹框外是否已关闭,非必传
            type: Boolean,
            default: {}
        },
        width: { //弹框宽度,非必传
            type: String,
            default: {}
        },
        subTitle: { //tab标题,必传
            type: String,
            default: {}
        },
    },
    components: {

    },
    setup(props, context) {

        const state = reactive({
            name: '',
        })

        const methods = {
            handleClose: () => {
                context.emit('close', false)
            }
        }
        return {
            ...toRefs(state),
            ...methods,
        }
    },
})
</script>

<style scoped lang='scss'>
.el-dialog__header {
    padding: 10px 10px 10px 20px;
}

.el-dialog__body {
    // max-height: 600px;
    overflow: hidden;
    overflow-y: auto;
}
</style>
父组件代码:
<template>
  <div class="about">
    <h1>This is an about page</h1>
    <el-button text @click="open()">
      弹 框
    </el-button>

    <DialogCom :title="'测试'" :sub-title="'详情'" :dialog-visible="visible" :click-close="true" :width="'50%'"
      @close="cancel">
      <span>
        It should be noted that the content will not be aligned in center by
        default
      </span>
      <div class="dialog-footer">
        <el-button @click="cancel()">取 消</el-button>
        <el-button type="primary" @click="cancel()">
          确 定
        </el-button>
      </div>
    </DialogCom>
  </div>
</template>

<script lang='ts'>
import { defineComponent, reactive, toRefs, SetupContext } from 'vue'
import DialogCom from "@/components/DialogCom.vue"
export default defineComponent({
  // name: '',
  props: {
  },
  components: {
    DialogCom
  },
  setup(props) {

    const state = reactive({
      // name: '',
      visible: false,
    })
    const methods = {
      open: () => {
        state.visible = true
      },
      cancel: () => {
        state.visible = false
      }
    }
    return {
      ...toRefs(state),
      ...methods
    }
  },
})
</script>

<style scoped lang='scss'>
@media (min-width: 1024px) {
  .about {
    min-height: 100vh;
    display: flex;
    align-items: center;
  }
}

.dialog-footer {
  text-align: center;
  margin-top: 20px;
}
</style>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值