vue中scss語法的使用你了解嗎
更新時(shí)間:2022年03月31日 11:38:15 作者:小渣亮
這篇文章主要為大家詳細(xì)介紹了vue中scss語法的使用,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助
vue之scss語法使用
引入scss文件
css / test.scss
$testColor:red;
home.vue
<!-- 描述: 作者:xzl 時(shí)間:03月30日190506 --> <template> <div class="Home"> Home <div class="test">測(cè)試</div> <div class="small-title">小標(biāo)題</div> </div> </template> <script> export default { name: 'Home', components: {}, data() { return {} }, methods: {} } </script> <style lang="scss" scoped> @import './css/test.scss'; $titleColor: red; $smallTitleColor: #a22; .Home { .test { color: $testColor; } .small-title { color: $smallTitleColor; } } </style>
效果
scss定義一個(gè)變量
<!-- 描述: 作者:xzl 時(shí)間:03月30日190506 --> <template> <div class="Home"> Home <div class="test">測(cè)試</div> <div class="small-title">小標(biāo)題</div> </div> </template> <script> export default { name: 'Home', components: {}, data() { return {} }, methods: {} } </script> <style lang="scss" scoped> $titleColor: red; $smallTitleColor: #a22; .Home { .test { color: $titleColor; } .small-title { color: $smallTitleColor; } } </style>
效果
scss里面使用算法 ±*/
.test { width: 50px * 2; height: calc(90px / 3); border: 1px solid #ccc; }
效果
定義mixin函數(shù)
@mixin text-overflow($width: 100%, $display: 'block') { width: $width; display: $display; white-space: nowrap; -ms-text-overflow: ellipsis; text-overflow: ellipsis; overflow: hidden; } .Home { .test { width: 50px * 2; height: calc(90px / 3); border: 1px solid #ccc; @include text-overflow(100px); } .small-title { width: 80px; @include text-overflow(80px); } }
效果
使用占位符 padding margin等
<!-- 描述: 作者:xzl 時(shí)間:03月30日190506 --> <template> <div class="Home"> Home <div class="test">我就是一個(gè)</div> <div class="small-title">我是小白兔</div> </div> </template> <style lang="scss" scoped> %pt5 { padding-top: 5px; } %mt10 { margin-top: 10px; } .Home { .test { @extend %mt10; width: 50px * 2; height: calc(90px / 3); border: 1px solid #ccc; } .small-title { @extend %pt5; width: 80px; } } </style>
效果
繼承 @entend XX
<!-- 描述: 作者:xzl 時(shí)間:03月30日190506 --> <template> <div class="Home"> <div class="caiji">我是菜雞</div> </div> </template> <style lang="scss" scoped> %pt5 { padding-top: 5px; } .testClass { font-size: 30px; color: #ff0; } .Home { .caiji { @extend %pt5; @extend .testClass; } } </style>
效果
總結(jié)
本篇文章就到這里了,希望能夠給你帶來幫助,也希望您能夠多多關(guān)注腳本之家的更多內(nèi)容!
相關(guān)文章
Vue使用Echarts實(shí)現(xiàn)立體柱狀圖
這篇文章主要為大家詳細(xì)介紹了Vue使用Echarts實(shí)現(xiàn)立體柱狀圖,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-09-09element-ui 限制日期選擇的方法(datepicker)
本篇文章主要介紹了element-ui 限制日期選擇的方法(datepicker),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-05-05Elementui表格組件+sortablejs實(shí)現(xiàn)行拖拽排序的示例代碼
這篇文章主要介紹了Elementui表格組件+sortablejs實(shí)現(xiàn)行拖拽排序,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-08-08vue中el-tree增加節(jié)點(diǎn)后如何重新刷新
這篇文章主要介紹了vue中el-tree增加節(jié)點(diǎn)后如何重新刷新,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-08-08vite+vue3中require?is?not?defined問題及解決
這篇文章主要介紹了vite+vue3中require?is?not?defined問題及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-05-05