vue学习——集成sass

安装

bash 复制代码
pnpm i sass sass-loader -D

在vite.config.ts文件配置:

bash 复制代码
export default defineConfig({
    css: {
      preprocessorOptions: {
        scss: {
          javascriptEnabled: true,
          additionalData: '@import "./src/styles/variable.scss";',
        },
      },
    },
    }
}

创建三个文件

src/styles/index.scss // 公共样式

src/styles/reset.scss // 清除默认样式

src/styles/variables.scss // 设置全局变量

bash 复制代码
// index.scss
@import './reset.scss'; // 注意:分号不能少!
bash 复制代码
// reset.scss
// 去npm中搜索reset.scss放到这里
/**
 * ENGINE
 * v0.2 | 20150615
 * License: none (public domain)
 */

*,
*:after,
*:before {
  box-sizing: border-box;

  outline: none;
}

html,
body,
div,
span,
applet,
object,
iframe,
h1,
h2,
h3,
h4,
h5,
h6,
p,
blockquote,
pre,
a,
abbr,
acronym,
address,
big,
cite,
code,
del,
dfn,
em,
img,
ins,
kbd,
q,
s,
samp,
small,
strike,
strong,
sub,
sup,
tt,
var,
b,
u,
i,
center,
dl,
dt,
dd,
ol,
ul,
li,
fieldset,
form,
label,
legend,
table,
caption,
tbody,
tfoot,
thead,
tr,
th,
td,
article,
aside,
canvas,
details,
embed,
figure,
figcaption,
footer,
header,
hgroup,
menu,
nav,
output,
ruby,
section,
summary,
time,
mark,
audio,
video {
  font: inherit;
  font-size: 100%;

  margin: 0;
  padding: 0;

  vertical-align: baseline;

  border: 0;
}

article,
aside,
details,
figcaption,
figure,
footer,
header,
hgroup,
menu,
nav,
section {
  display: block;
}

body {
  line-height: 1;
}

ol,
ul {
  list-style: none;
}

blockquote,
q {
  quotes: none;
  &:before,
  &:after {
    content: '';
    content: none;
  }
}

sub,
sup {
  font-size: 75%;
  line-height: 0;

  position: relative;

  vertical-align: baseline;
}
sup {
  top: -.5em;
}
sub {
  bottom: -.25em;
}

table {
  border-spacing: 0;
  border-collapse: collapse;
}

input,
textarea,
button {
  font-family: inhert;
  font-size: inherit;

  color: inherit;
}

select {
  text-indent: .01px;
  text-overflow: '';

  border: 0;
  border-radius: 0;

  -webkit-appearance: none;
  -moz-appearance: none;
}
select::-ms-expand {
  display: none;
}

code,
pre {
  font-family: monospace, monospace;
  font-size: 1em;
}
bash 复制代码
// variables.scss
$color: skyblue

App.vue中测试一下,是否已清除默认样式,全局变量是否生效。

相关推荐
婷婷_1729 分钟前
【PCIe验证每日学习·Day23】Completion 完成包全机制深度解析
学习·程序人生·芯片·completion·pcie 验证·outsatanding·id路由
羊小猪~~23 分钟前
Redis学习笔记(数据类型、持久化、事件、管道、发布订阅等)
开发语言·数据库·c++·redis·后端·学习·缓存
结衣结衣.34 分钟前
【Linux】命名管道的妙用:实现进程控制与实时字符交互
linux·运维·开发语言·学习·操作系统·交互
red_redemption43 分钟前
自由学习记录(151)
学习
charlie1145141911 小时前
嵌入式C++教程实战之Linux下的单片机编程:从零搭建 STM32 开发工具链(3)WSL2 USB 透传,让 ST-Link 穿越虚拟化边界
c++·stm32·单片机·学习·嵌入式
AI成长日志1 小时前
【datawhale】hello agents开源课程学习记录第6章:智能体框架开发实践
学习·开源
東雪木2 小时前
Java学习——重载 (Overload) 与重写 (Override) 的核心区别、底层实现规则
java·开发语言·jvm·学习·java面试
zl_dfq2 小时前
Python学习4 之 【函数】(函数的相关语法、下划线的使用、global与nonlocal关键字)
python·学习
承渊政道2 小时前
【优选算法】(实战剖析链表核心操作技巧)
开发语言·数据结构·c++·vscode·学习·算法·链表
li星野2 小时前
DeepSeek-V3介绍
学习