当前位置: 首页 > news >正文

Vue3中使用:deep修改element-plus的样式无效怎么办?

前言:当我们用 vue3 :deep() 处理 elementui 中 el-dialog_body和el-dislog__header 的时候样式一直无法生效,遇到这种情况怎么办?

解决办法:

1.直接在 dialog 上面增加class 我试过,也不起作用,最后用这种方法解决的,dialog 外面直接包一层 div
2.将样式单独写一个style标签进行覆盖---此方式由于样式写在外面,可能会影响整个项目的全局样式,--慎重考虑

需求:需要将el-drawer__header的底部的外边距去掉
方式一:
修改前:
在这里插入图片描述修改后:
在这里插入图片描述
生效方式:1.在最外层加一层在el-dialog外面包一层


2.主要是vue3中deep会因为最外层没有根节点失效的问题,只需要加一个根节点,deep就有效了
需要注意的是 :deep(这里面只能包一个)

<template><div class="dialog"><el-drawer v-model="drawerDialog" direction="rtl" @close="handleClose" size="50%"><template #header><div class="header"><h4>订单详情----订单编号(23232434343)</h4></div></template><template #default><div class="content"><div class="item-info"><div class="wrap"><div class="top"><div class="left"><div class="line"></div><div class="title">购方信息</div></div><div class="right"><el-button type="primary" plain>编辑</el-button></div></div><div class="info-list"></div></div></div></div></template><template #footer><div style="flex: auto"><el-button @click="handleClose">取消</el-button><el-button type="primary" @click="confirm">确定</el-button></div></template></el-drawer></div>
</template><script setup>
import { watchEffect, ref } from 'vue';
const emit = defineEmits(["close"])
const props = defineProps({visible: {type: Boolean,default: false}
})
const drawerDialog = ref(false);//确定的回调函数
const confirm = () => {}//取消的回调函数
const handleClose = () => {drawerDialog.value = false;emit('close');
}watchEffect(() => {if (props.visible) {drawerDialog.value = props.visible;}
})</script><style scoped lang="scss">
.dialog {:deep(.el-drawer__header) {margin: 0;}
}.header {background-color: #fff;height: 40px;
}.content {background-color: #EDEFEE;.item-info {.wrap {.top {display: flex;justify-content: space-between;.left {display: flex;align-items: center;.line {height: 15px;width: 4px;background-color: #07f;}.title {font-size: 16px;font-weight: bold;}}.right {}}.info-list {}}}
}
</style>

方式二:

<template> <el-drawer v-model="drawerDialog" direction="rtl" @close="handleClose" size="50%"><template #header><div class="header"><h4>订单详情----订单编号(23232434343)</h4></div></template><template #default><div class="content"><div class="item-info"><div class="wrap"><div class="top"><div class="left"><div class="line"></div><div class="title">购方信息</div></div><div class="right"><el-button type="primary" plain>编辑</el-button></div></div><div class="info-list"></div></div></div></div></template><template #footer><div style="flex: auto"><el-button @click="handleClose">取消</el-button><el-button type="primary" @click="confirm">确定</el-button></div></template></el-drawer>
</template><script setup>
import { watchEffect, ref } from 'vue';
const emit = defineEmits(["close"])
const props = defineProps({visible: {type: Boolean,default: false}
})
const drawerDialog = ref(false);//确定的回调函数
const confirm = () => {}//取消的回调函数
const handleClose = () => {drawerDialog.value = false;emit('close');
}watchEffect(() => {if (props.visible) {drawerDialog.value = props.visible;}
})</script><style>
.el-drawer__header {margin: 0;
}
</style>
<style scoped lang="scss">.header {background-color: #fff;height: 40px;
}.content {background-color: #EDEFEE;.item-info {.wrap {.top {display: flex;justify-content: space-between;.left {display: flex;align-items: center;.line {height: 15px;width: 4px;background-color: #07f;}.title {font-size: 16px;font-weight: bold;}}.right {}}.info-list {}}}
}
</style>

修改前:
在这里插入图片描述修改后:
在这里插入图片描述

http://www.lryc.cn/news/487588.html

相关文章:

  • 具身智能之Isaac Gym使用
  • 【大数据学习 | Spark】spark-shell开发
  • 《Python制作动态爱心粒子特效》
  • Jmeter 如何导入证书并调用https请求
  • Python程序15个提速优化方法
  • 足球虚拟越位线技术FIFA OT(二)
  • centos7.9单机版安装K8s
  • 图像编辑一些概念:Image Reconstruction与Image Re-generation
  • 【STM32】在 STM32 USB 设备库添加新的设备类
  • 【Redis】Redis实现的消息队列
  • # Spring事务
  • Java学习笔记--数组常见算法:数组翻转,冒泡排序,二分查找
  • ARM 架构(Advanced RISC Machine)精简指令集计算机(Reduced Instruction Set Computer)
  • 7.STM32之通信接口《精讲》之USART通信---多字节数据收发(数据包的模式:HEX数据包和文本数据包)
  • 基于Vue+SpringBoot的求职招聘平台
  • WebRTC 和 WebSocket
  • 小车综合玩法--5.画地为牢
  • 数据库课程设计全流程:方法与实例解析
  • 用Ruby编写一个自动化测试脚本,验证网站登录功能的正确性。
  • 跳表 | 基本概念 | 代码实现
  • 分数加减
  • 基于卷积神经网络的皮肤病识别系统(pytorch框架,python源码,GUI界面,前端界面)
  • QT与嵌入式——获取网络实时时间
  • 优化装配,提升品质:虚拟装配在汽车制造中的关键作用
  • Bug的严重等级和优先级别与分类
  • 游戏引擎学习第13天
  • bind返回失败(ctrl+c)结束后不能再次加载
  • 菜鸟驿站二维码/一维码 取件识别功能
  • 23种设计模式-备忘录(Memento)设计模式
  • 搜维尔科技:Manus遥操作五指机械手专用手套惯性高精度虚拟现实