Vue's scss syntax usage

Vue's scss syntax usage

import scss file

css / test.scss

$testColor:red;

home.view

<!--
描述:
  作者:xzl
  时间:0330190506
-->
<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>
  • Effect
    insert image description here

scss defines a variable

<!--
描述:
  作者:xzl
  时间:0330190506
-->
<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>
  • Effect
    insert image description here

The algorithm ±*/ is used in scss

  .test {
    
    
    width: 50px * 2;
    height: calc(90px / 3);
    border: 1px solid #ccc;
  }
  • Effect
    insert image description here

Define the mixin function

@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);
  }
}
  • Effect
    insert image description here

Use placeholder padding margins etc.

<!--
描述:
  作者:xzl
  时间:0330190506
-->
<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>

  • Effect
    insert image description here

Inherit @entend XX

<!--
描述:
  作者:xzl
  时间:0330190506
-->
<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>

  • Effect
    insert image description here

Guess you like

Origin blog.csdn.net/weixin_43845137/article/details/123854931