1.全局控制,避免樣式散亂css
2.代碼簡潔,開發快速 函數式編程大量使用函數,減小了代碼的重複,所以程序比較短,開發速度較快html
3.接近天然語言,易於理解 函數式編程的自由度很高,能夠寫出很接近天然語言的代碼編程
4.更方便的代碼管理sass
5.書寫樣式成爲一門藝術markdown
.card-title {
font: "PingFang-SC-medium";
color: #333;
font-size: 18px;
}
.card-title {
font: "PingFang-SC-regular";
font-size: 14px;
color: #333;
}
複製代碼
// 申明less函數
.mixin-font-class(@fontColor: yellow; @fontSize; @fontFamily) {
font-family: @fontFamily;
font-size: @fontSize;
color: @fontColor;
}
複製代碼
h6 {
.mixin-font-class(@fontColor:red;@fontSize:12px;@fontFamily:"PingFang-SC-medium");
}
h2{
.mixin-font-class(@fontColor:blue;@fontSize:15px;@fontFamily:"PingFang-SC-regular");
}
複製代碼
在Vue-cli模式中less
// 添加全局less
pluginOptions: {
'style-resources-loader': {
preProcessor: 'less',
patterns: [
resolve('./src/less/theme.less')
]
}
},
複製代碼
// 在任何組件中或者less文件中使用
<style lang="less" scoped>
.breadTop {
height: 60px;
display: flex;
align-items: center;
justify-content: space-between;
padding-right: 15px;
h6 {
.mixin-font-class(@fontColor:red;@fontSize:12px;@fontFamily:"PingFang-SC-medium");
}
h2{
.mixin-font-class(@fontColor:blue;@fontSize:15px;@fontFamily:"PingFang-SC-regular");
}
}
</style>
複製代碼
$font-normal-color = #222;
$font-light-color = #333;
@mixin font-class($fontFamily, $fontSize, $fontColor) {
font-family: $fontFamily;
font-size: $fontSize;
color: $fontColor;
}
@mixin font-large($size: 14px, $color: $font-normal-color) {
@include font-class($font-family-medium, $size, $color);
}
@mixin font-normal($size: 14px, $color: $font-light-color) {
@include font-class($font-family-regular, $size, $color);
}
複製代碼
.form-title {
@include font-large(16px, red);
}
.form-text {
@include font-large(12px, blue);
}
複製代碼
注意less函數的參數使用的@,scss使用的$函數式編程