解決vue scoped scss 無效的問題
今天遇到scoped內(nèi)部的scss設(shè)置無效,解決辦法如下:
/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; } }}
補(bǔ)充知識:【vue scoped 樣式修改 】框架或插件組件樣式更改及/deep/ 警告
前言
在做vue項(xiàng)目的時候,很多人應(yīng)該已經(jīng)碰到在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> /* 使用 scoped 更改的組件樣式。 */ /* 此處只是舉個栗子使用,沒有經(jīng)過驗(yàn)證。很多人會下面這摸寫,但是發(fā)現(xiàn)改變不了B組件的樣式,其實(shí)是 scoped 局部的,所以不能。 .boxA .my { color:red; } */ .boxA /deep/ .my { color:red; }</style>
修改 vue 插件或者 框架內(nèi)組件使用
語法: .自己定義的類名 /deep/ .組件內(nèi)的類名 { /* 代碼塊 */ }
看下圖:
修改組件樣式三種方式
以下例子以 vux 來弄。 /deep/ 和 >>> 在vue中會自動生成選擇器的選擇屬性,你在頁面中,會看到控制臺中的會有 [data-v-xxxxxx] 的。
注意:在谷歌中,也有這個 /deep/ 中間選擇器,但是谷歌放棄這個,如果在你控制臺出現(xiàn)下面的圖片的警告,證明你寫錯了,多寫了 /deep/ https://www.chromestatus.com/features/4964279606312960
vue /deep/ 警告
解決方案:只要在頁面中去查找下即可,利用vue渲染后會把所有的,會在控制臺能看到
第一種:使用 /deep/
推薦的。看下面例子。注意:使用 cass 和 less 只能使用 /deep/ 這個方法
<template> <div class='box-out'> <step v-model='step1' background-color=’#fbf9fe’> <step-item description='step 1'></step-item> <step-item description='step 2'></step-item> <step-item description='step 3'></step-item> </step> </div></template><script>import { Step, StepItem, XButton, XHr } from ’vux’export default { name: ’box’, data () { return { step1: 1, step2: 0 } },components: { Step, StepItem, XButton, XHr }}</script><style scoped> /* 修改樣式 通過使用 box-out 的class類,找到下面組件內(nèi)的class類,中間必須得使用 /deep/ 才能找到下面的class類。 */ .box-out /deep/ .xxxxx組件樣式類 { color: red; }</style>
方法二:使用 >>>
使用這三個大于號就可以找到,跟上面的 /deep/ 差不多。
<template> <div class='box-out'> <step v-model='step1' background-color=’#fbf9fe’> <step-item description='step 1'></step-item> <step-item description='step 2'></step-item> <step-item description='step 3'></step-item> </step> </div></template><script>import { Step, StepItem, XButton, XHr } from ’vux’export default { name: ’box’, data () { return { step1: 1, step2: 0 } },components: { Step, StepItem, XButton, XHr }}</script><style scoped> /* 修改樣式 通過使用 box-out 的class類,找到下面組件內(nèi)的class類,中間必須得使用 >>> 才能找到下面的class類。 */ .box-out >>> .xxxxx組件樣式類 { color: red; }</style>
方法三:使用全局樣式表(不推薦)
前面兩種方式是都是局部的(推薦),也是可以通過全局樣式表改,當(dāng)然記得在外面添加命名空間(不懂css 的命名空間的話,自行百度)。這個推不推薦的得看個人。希望能夠根據(jù)業(yè)務(wù)需求進(jìn)行增加修改。
<!-- 情況下,引入全局得樣式,或者是直接在 app.vue 文件中寫全局得。下面是在全局得app.vue中寫 --><template> <div id='app'> <router-view/> </div></template><script>export default { name: ’App’}</script><style>/* 上面沒加 scoped 屬性,所以全局樣式 */ .box-out .xxxxx組件樣式類 { color: red; }</style>
另外說點(diǎn)其他技巧
如果在瀏覽器中,看到當(dāng)前的 vue組件屬性 [data-v-xxxxxx] 的話,那么可以直接拿過來使用,碧如下面:
以上這篇解決vue scoped scss 無效的問題就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. .NET SkiaSharp 生成二維碼驗(yàn)證碼及指定區(qū)域截取方法實(shí)現(xiàn)2. Django使用HTTP協(xié)議向服務(wù)器傳參方式小結(jié)3. IntelliJ IDEA創(chuàng)建web項(xiàng)目的方法4. ASP.NET MVC通過勾選checkbox更改select的內(nèi)容5. HTTP協(xié)議常用的請求頭和響應(yīng)頭響應(yīng)詳解說明(學(xué)習(xí))6. CentOS郵件服務(wù)器搭建系列—— POP / IMAP 服務(wù)器的構(gòu)建( Dovecot )7. ASP中實(shí)現(xiàn)字符部位類似.NET里String對象的PadLeft和PadRight函數(shù)8. Android studio 解決logcat無過濾工具欄的操作9. 存儲于xml中需要的HTML轉(zhuǎn)義代碼10. .NET 6實(shí)現(xiàn)滑動驗(yàn)證碼的示例詳解
