vue中scss語法的使用你了解嗎
更新時間:2022年03月31日 11:38:15 作者:小渣亮
這篇文章主要為大家詳細介紹了vue中scss語法的使用,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助
vue之scss語法使用
引入scss文件
css / test.scss
$testColor:red;
home.vue
<!--
描述:
作者:xzl
時間:03月30日190506
-->
<template>
<div class="Home">
Home
<div class="test">測試</div>
<div class="small-title">小標題</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定義一個變量
<!--
描述:
作者:xzl
時間:03月30日190506
-->
<template>
<div class="Home">
Home
<div class="test">測試</div>
<div class="small-title">小標題</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函數
@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
時間:03月30日190506
-->
<template>
<div class="Home">
Home
<div class="test">我就是一個</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
時間: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>
效果

總結
本篇文章就到這里了,希望能夠給你帶來幫助,也希望您能夠多多關注腳本之家的更多內容!
相關文章
element-ui 限制日期選擇的方法(datepicker)
本篇文章主要介紹了element-ui 限制日期選擇的方法(datepicker),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-05-05
Elementui表格組件+sortablejs實現(xiàn)行拖拽排序的示例代碼
這篇文章主要介紹了Elementui表格組件+sortablejs實現(xiàn)行拖拽排序,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2019-08-08
vite+vue3中require?is?not?defined問題及解決
這篇文章主要介紹了vite+vue3中require?is?not?defined問題及解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-05-05

