Vue随笔【::v-deep 解决 样式污染的bug】

        在Vue项目中,尤其是在使用组件化开发时,我们时常需要修改组件内部的样式,为避免全局样式污染,需使用Vue提供的<style scoped>,但Vue的样式封装特性(如<style scoped>)会阻止外部样式直接作用于组件内部,深度选择器 ::v-deep 应运而生 !

1、分析

        原因在于设置样式时使用了第三方组件库共有类名,并且没有写在scoped中,致使页面切换(无刷新时)样式污染

// 【运营统计组件】日期选择器样式
  .ivu-picker-panel-shortcut {
      border: 1px solid rgb(39, 38, 38);
      border-radius: 10px;
      width: 60%;
      height: 28px;
      margin-top: 20px;
      margin-left: 10px;
      margin-right: 10px;
      text-align: center;
      font-size: smaller;
  }


// 【license组件】日期选择器样式
.ivu-picker-panel-shortcut {
    border: 1px solid rgb(39, 38, 38);
    border-radius: 10px;
    width: 68%;
    height: 28px;
    margin-top: 10px;
    margin-left: 6px;
    margin-right: 6px;
    text-align: center;
    font-size: smaller;
}

2、解决

        vue组件 scoped 结合 深度选择器【::v-deep 】穿透样式

//  使用深度选择器 ::v-deep
// 【样式穿透】解决样式冲突问题 【license组件】
::v-deep .ivu-picker-panel-shortcut {
    border: 1px solid rgb(39, 38, 38);
    border-radius: 10px;
    width: 68%;
    height: 28px;
    margin-top: 10px;
    margin-left: 6px;
    margin-right: 6px;
    text-align: center;
    font-size: smaller;
}


// 【样式穿透】解决样式冲突问题【运营统计组件】
  ::v-deep .ivu-picker-panel-shortcut {
      border: 1px solid rgb(39, 38, 38);
      border-radius: 10px;
      width: 60%;
      height: 28px;
      margin-top: 20px;
      margin-left: 10px;
      margin-right: 10px;
      text-align: center;
      font-size: smaller;
  }

相关推荐

  1. Vue随笔【::v-deep 解决 样式污染bug

    2024-07-20 09:28:01       18 阅读
  2. vue使用样式渗透/deep/ :deep() :global()

    2024-07-20 09:28:01       30 阅读
  3. Vue.js 中::v-deep

    2024-07-20 09:28:01       30 阅读
  4. 深度选择器/deep/、::v-deep、:deep区别

    2024-07-20 09:28:01       37 阅读
  5. vue 深度作用选择器 >>>、/deep/、::v-deep

    2024-07-20 09:28:01       44 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-20 09:28:01       52 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-20 09:28:01       54 阅读
  3. 在Django里面运行非项目文件

    2024-07-20 09:28:01       45 阅读
  4. Python语言-面向对象

    2024-07-20 09:28:01       55 阅读

热门阅读

  1. 一种全局数据变化而且是多个的通知实现

    2024-07-20 09:28:01       18 阅读
  2. 极狐GitLab如何配置使用独立数据库?

    2024-07-20 09:28:01       17 阅读
  3. python 66 个冷知识 0716

    2024-07-20 09:28:01       16 阅读
  4. 【数据库技术NoSQL】MongoDB和Cassandra的使用

    2024-07-20 09:28:01       16 阅读
  5. live555搭建实时播放rtsp服务器

    2024-07-20 09:28:01       18 阅读
  6. 服务器相关总结

    2024-07-20 09:28:01       16 阅读
  7. ES6 字符串的新增方法(二十)

    2024-07-20 09:28:01       14 阅读
  8. C语言初学者入门指南

    2024-07-20 09:28:01       13 阅读
  9. 如何看待中国信息协会2024年网络安全大赛

    2024-07-20 09:28:01       14 阅读
  10. Symfony框架概述

    2024-07-20 09:28:01       16 阅读
  11. go reflect的工程使用

    2024-07-20 09:28:01       17 阅读
  12. RKE部署k8s

    2024-07-20 09:28:01       18 阅读
  13. 关于取模的相关注意

    2024-07-20 09:28:01       17 阅读
  14. nodejs使用request后端访问第三方接口

    2024-07-20 09:28:01       17 阅读