今天遇到scoped内部的scss设置无效,解决办法如下:
/deep/
<style scoped lang="scss">.position-el-steps { /deep/ .el-step.is-vertical { .el-step__description { margin-top: -20px; } .el-step__line { border-left: 2px dashed #c0c4cc; background-color: transparent; visibility: visible !important; } }}补充知识:【vue scoped 样式修改 】框架或插件组件样式更改及/deep/ 警告
前言
在做vue项目的时候,很多人应该已经碰到在vue 组件中,style 局部修改样式更改不了
<!-- 这个是 B 组件 --><template> <div> <h1 class="my">我是B组件</h1> </div></template><!-- A组件 --><template> <div class="boxA"> <A/> </div></template><script> import A from './a' export default { name: 'index', components:{ A } }</script><style scoped> .boxA /deep/ .my { color:red; }</style>修改 vue 插件或者 框架内组件使用
语法: .自己定义的类名 /deep/ .组件内的类名 { }
看下图:
修改组件样式三种方式
以下例子以 vux 来弄。 /deep/ 和 >>> 在vue中会自动生成选择器的选择属性,你在页面中,会看到控制台中的会有 [data-v-xxxxxx] 的。
注意:在谷歌中,也有这个 /deep/ 中间选择器,但是谷歌放弃这个,如果在你控制台出现下面的图片的警告,证明你写错了,多写了 /deep/ https://ponents: { Step, StepItem, XButton, XHr }}</script><style scoped> .box-out >>> .xxxxx组件样式类 { color: red; }</style>
方法三:使用全局样式表(不推荐)
前面两种方式是都是局部的(推荐),也是可以通过全局样式表改,当然记得在外面添加命名空间(不懂css 的命名空间的话,自行百度)。这个推不推荐的得看个人。希望能够根据业务需求进行增加修改。
<!-- 情况下,引入全局得样式,或者是直接在 app.vue 文件中写全局得。下面是在全局得app.vue中写 --><template> <div id="app"> <router-view/> </div></template><script>export default { name: 'App'}</script><style> .box-out .xxxxx组件样式类 { color: red; }</style>另外说点其他技巧
如果在浏览器中,看到当前的 vue组件属性 [data-v-xxxxxx] 的话,那么可以直接拿过来使用,碧如下面:
以上这篇解决vue scoped scss 无效的问题就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。