Vue Element-Plus 自定义 Dialog弹框组件时 scss 的样式没作用

<!--
 * @Date: 2024-03-25 16:55:53
 * @LastEditors: zhong
 * @LastEditTime: 2024-03-29 16:19:12
 * @FilePath: \app-admin\src\components\SystemDialog\SystemDialog.vue
-->
<template>
    <div>
        <el-dialog :model-value="props.visible" :title="props.title" :width="props.width + 'px'"
            :height="props.height + 'px'" :before-close="onClose" :close-on-click-modal="false" :append-to-body="true">
            <!-- 内容显示区 -->
            <div class="container" :style="{ height: height + 'px' }">
                <slot name="content"></slot>
            </div>
            <template #footer>
                <div class="dialog-footer">
                    <el-button @click="onClose" type="danger">取消</el-button>
                    <el-button type="success" @click="onConfirm">
                        确认
                    </el-button>
                </div>
            </template>
        </el-dialog>
    </div>
</template>

<script setup lang="ts">
// 定义弹窗数据类型
interface dialogProps {
    title: string,
    visible: boolean,
    width: number,
    height: number
}

// 接收父组件传递的参数
const props = withDefaults(defineProps<dialogProps>(), {
    title: "新增",
    visible: false,
    width: 630,
    height: 280
})
// 注册事件
const emit = defineEmits(["onClose", "onConfirm"])

// 关闭事件
const onClose = () => {
    emit("onClose");
}
// 提交事件
const onConfirm = () => {
    emit("onConfirm");
}
</script>


<style lang="scss" scoped>
.container {
    overflow-x: inherit;
    overflow-y: auto;
}

:deep(.el-dialog) {
    padding: 0;
    border-top-left-radius: 7px !important;
    border-top-right-radius: 7px !important;

    .el-dialog__header {
        margin-right: 0px;
        padding-top: 10px;
        border-top-left-radius: 7px !important;
        border-top-right-radius: 7px !important;
        background-color: rgb(11, 62, 37) !important;

        .el-dialog__title {
            padding: 16px;
            color: #FFF;
            font-size: 16px;
            font-weight: 600;
        }
    }

    .el-dialog__headerbtn {
        .el-dialog__close {
            color: #FFF;
        }
    }

    .el-dialog__body {
        padding: 10px;
    }

    .el-dialog__footer {
        border-top: 1px solid #e8eaec !important;
        padding: 10px;
    }
}
</style>

问题代码

el-dialog :model-value="props.visible" :title="props.title" :width="props.width + 'px'"
            :height="props.height + 'px'" :before-close="onClose" :close-on-click-modal="false" :append-to-body="true">
         
        </el-dialog>

解决方法

去掉 :append-to-body=“true”

修改后

<!--
 * @Date: 2024-03-25 16:55:53
 * @LastEditors: zhong
 * @LastEditTime: 2024-03-29 16:22:31
 * @FilePath: \app-admin\src\components\SystemDialog\SystemDialog.vue
-->
<template>
    <div>
        <el-dialog :model-value="props.visible" :title="props.title" :width="props.width + 'px'"
            :height="props.height + 'px'" :before-close="onClose" :close-on-click-modal="false">
            <!-- 内容显示区 -->
            <div class="container" :style="{ height: height + 'px' }">
                <slot name="content"></slot>
            </div>
            <template #footer>
                <div class="dialog-footer">
                    <el-button @click="onClose" type="danger">取消</el-button>
                    <el-button type="success" @click="onConfirm">
                        确认
                    </el-button>
                </div>
            </template>
        </el-dialog>
    </div>
</template>

<script setup lang="ts">
// 定义弹窗数据类型
interface dialogProps {
    title: string,
    visible: boolean,
    width: number,
    height: number
}

// 接收父组件传递的参数
const props = withDefaults(defineProps<dialogProps>(), {
    title: "新增",
    visible: false,
    width: 630,
    height: 280
})
// 注册事件
const emit = defineEmits(["onClose", "onConfirm"])

// 关闭事件
const onClose = () => {
    emit("onClose");
}
// 提交事件
const onConfirm = () => {
    emit("onConfirm");
}
</script>


<style lang="scss" scoped>
.container {
    overflow-x: inherit;
    overflow-y: auto;
}

:deep(.el-dialog) {
    padding: 0;
    border-top-left-radius: 7px !important;
    border-top-right-radius: 7px !important;

    .el-dialog__header {
        margin-right: 0px;
        padding-top: 10px;
        border-top-left-radius: 7px !important;
        border-top-right-radius: 7px !important;
        background-color: rgb(11, 62, 37) !important;

        .el-dialog__title {
            padding: 16px;
            color: #FFF;
            font-size: 16px;
            font-weight: 600;
        }
    }

    .el-dialog__headerbtn {
        .el-dialog__close {
            color: #FFF;
        }
    }

    .el-dialog__body {
        padding: 10px;
    }

    .el-dialog__footer {
        border-top: 1px solid #e8eaec !important;
        padding: 10px;
    }
}
</style>

最近更新

  1. TCP协议是安全的吗?

    2024-03-30 05:26:03       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-03-30 05:26:03       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-03-30 05:26:03       19 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-03-30 05:26:03       20 阅读

热门阅读

  1. Redis--缓存常用的 3 种读写策略

    2024-03-30 05:26:03       17 阅读
  2. html目录

    2024-03-30 05:26:03       20 阅读
  3. PyTorch数据结构

    2024-03-30 05:26:03       19 阅读
  4. UniApp中获取安卓设备的唯一标识符

    2024-03-30 05:26:03       16 阅读
  5. MySQL 架构

    2024-03-30 05:26:03       19 阅读
  6. 大模型提示工程之Prompt框架和示例

    2024-03-30 05:26:03       20 阅读
  7. 小米su7定价21.59万元对汽车市场的影响

    2024-03-30 05:26:03       25 阅读
  8. ChatGPT 商业金矿(下)

    2024-03-30 05:26:03       41 阅读
  9. MySQL分表后,如何做分页查询?

    2024-03-30 05:26:03       19 阅读
  10. python项目练习——8.图像处理应用程序

    2024-03-30 05:26:03       19 阅读
  11. ubuntu22.04,放弃ibus,改用fcitx5

    2024-03-30 05:26:03       20 阅读
  12. 二、CentOS基础配置(1.网络与包管理)

    2024-03-30 05:26:03       16 阅读
  13. clickhouse 查询group 分组最大值的一行数据。

    2024-03-30 05:26:03       17 阅读
  14. centos安装snap

    2024-03-30 05:26:03       16 阅读
  15. Flink 中 Slot 机制详解:概念、原理与开发实践

    2024-03-30 05:26:03       17 阅读