Fork me on github

sass的使用

 

sass的使用(vue3)

安装

npm i sass sass-loader@10.1.1 -D
npm install -g cnpm --registry=https://registry.npm.taobao.org
cnpm install node-sass@7.0.1

 

使用

 

$font:16px;
$color:red;
@function toRem($a){
    @return ($a/20)+rem;

vue.config.js

复制代码
const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
  transpileDependencies: true,
  runtimeCompiler: true,
  pluginOptions: {
      'style-resources-loader': {
          preProcessor: 'scss',
          patterns: []
      }
  }
})
复制代码

 

vue组件中

复制代码
<template>
  <div class="hello">
this is scss
<span class="test">嵌套</span>
  </div>
</template>

<script>
export default {
  name: 'HelloWorld',

}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="scss" scoped>
@import '../assets/styles/variables.scss';
$nav-color: #F90;
.hello {
  width: toRem(200);
  height: toRem(200);
  border: 1px solid #000;
  color: $color;
  .test{
    font-size: $font*2;
  }
}
</style>
复制代码

 

less的使用

安装版本

    "less": "^3.9.0",
    "less-loader": "^5.0.0",

 

样式引入

@color: red;
@font-size: 16px;
@width:100px;
@height:200px;

vue组件

复制代码
<template>
   <div>
      <p>这是less</p>
      <i>只需要在style节点加上lang="less"属性,即可可直接使用less</i>
   </div>
</template>

<script>
export default {
  name: 'tee',
  data () {
    return {}
  },
  components: {}
}
</script>

<style scoped lang="less">
//@import url('../assets/css/common.less');
div {
  width: @width;
  height: @height+100;
  border: 1px solid #000;
  background: @color;
  p{
    color: yellow
  }
}
</style>
复制代码

 

 

 

posted @   我の前端日记  阅读(37)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 字符编码:从基础到乱码解决
Copyright © 2021 LinCangHai
Powered by .NET 5.0 on Kubernetes
点击右上角即可分享
微信分享提示