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>
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 字符编码:从基础到乱码解决