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中测试一下,是否已清除默认样式,全局变量是否生效。

相关推荐
Miki Makimura2 分钟前
Reactor 模式实现:从 epoll 到高并发调试
运维·服务器·c++·学习
jiajixi1 小时前
go-swagger学习笔记
笔记·学习·golang
Mingze03142 小时前
C语言四大排序算法实战
c语言·数据结构·学习·算法·排序算法
东风西巷2 小时前
STranslate(翻译工具OCR工具) 中文绿色版
学习·ocr·电脑·软件需求
程序员东岸3 小时前
学完顺序表后,用 C 语言写了一个通讯录
数据结构·笔记·学习
拱-卒3 小时前
VB.NET入门学习教程
学习
爱偷懒的。。3 小时前
基于 WebSocket 协议的实时弹幕通信机制分析-抖音
网络·python·websocket·网络协议·学习·js
知识分享小能手4 小时前
微信小程序入门学习教程,从入门到精通,自定义组件与第三方 UI 组件库(以 Vant Weapp 为例) (16)
前端·学习·ui·微信小程序·小程序·vue·编程
Rock_yzh4 小时前
AI学习日记——深度学习
人工智能·python·深度学习·神经网络·学习
@小张要努力4 小时前
STM32学习记录-0.1 STM32外设
stm32·嵌入式硬件·学习