1. 安装插件
npm install sass --save-dev
  1. 在src文件夹下创建styles文件夹,并创建以下文件

  • index.scss: scss的入口文件
// 引入清除默认样式
@import './reset.scss';
  • 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;
}
  • variable.scss:scss的全局变量
// 配置scss全局变量
$color:red
  1. mian.ts文件引入scss
import '@/styles/index.scss'
  1. 配置vite.config.ts文件
export default defineConfig({
plugins: [
vue()
],
// scss全局变量配置
css: {
preprocessorOptions: {
scss: {
javascriptEnable: true,
additionalData: '@import "./src/styles/variable.scss";'
}
}
}
})
  1. 案例代码
<template>
<div><h1>测试代码</h1></div>
</template> <script setup lang="ts"></script> <style scoped lang="scss">
div {
h1 {
color: $color;
}
}
</style>
  • 由于引入了reset.scss清除样式,所以就没有h1的效果了,可以把reset.scss样式去掉感受效果
  • $color就是variable.scss中配置的全局变量

vue配置scss全局样式的更多相关文章

  1. React项目中使用less/scss&全局样式/变量

    使用create-react-app脚手架搭建初始化项目 > npm install -g create-react-app > npx create-react-app my-app c ...

  2. vue文件引入全局样式导致样式重复

    通常项目中src下的子目录都会有一个style文件夹,专门用来存放全局的样式文件. 这个style文件夹下,一般有reset.css.var.scss.mixin.scss.class.scss.in ...

  3. vue 配置scss流程

    引入相关的node包 npm install --save style-loader sass-loader node-sass file-loader 安装好之后,为了可以在.vue和.scss中使 ...

  4. vue 配置了全局的http拦截器,单独某个组件不需要这个拦截器,如何设置

    之前写过关于全局配置http拦截器的随笔,现在有个需求,在微信支付时,生成二维码,页面显示一个遮罩层,二维码页面需要每两秒请求一次接口,若返回结果为已支付,则进行页面跳转,但因为全局http中load ...

  5. 项目前端 - vue配置 | axios配置 | cookies配置 | element-ui配置 | bootstrap配置

    vue项目创建 环境 1.傻瓜式安装node: 官网下载:https://nodejs.org/zh-cn/ ​ 2.安装cnpm: >: npm install -g cnpm --regis ...

  6. 第三章、vue-项目前端 - vue配置 | axios配置 | cookies配置 | element-ui配置 | bootstrap配置

    目录 vue项目创建 环境 创建项目 重构项目目录 文件修订:目录中非配置文件的多余文件可以移除 全局配置:全局样式.配置文件 axios前后台交互 cookies操作 element-ui页面组件框 ...

  7. vue中修改swiper样式

    问题 vue单文件组件中无法修改swiper样式. 解决 1,单文件组件中:新增一个style 不加scoped 让它最终成为全局样式.只在其中操作swiper的样式. <style lang= ...

  8. vue配置 less 全局变量

    在使用Vue开发的过程中,通常会用到一些样式的全局变量,如果在每个组件中引入就太繁琐了,维护性也不好,因此全局引入是个不错的想法.下面以less为例,记录一下全局引入less变量的步骤: 1.首先安装 ...

  9. react抽离配置文件、配置@符号、调整src文件夹---配置scss、编写项目的页面结构、创建各个页面 src/views、开始路由、入口文件处修改代码、修改App.js布局文件、添加底部的导航布局、构建个人中心。。。声明式跳转路由、使用React UI库请求渲染首页数据、

    1.回顾 2.react项目的配置 react默认创建的项目配置文件在 node_modules/react-scripts 文件夹内部 2.1 抽离配置文件 cnpm run eject cnpm ...

  10. taro 组件的外部样式和全局样式

    自定义组件对应的样式文件,只对该组件内的节点生效. 编写组件样式时,需要注意以下几点: 组件和引用组件的页面不能使用 id 选择器(#a).属性选择器([a])和标签名选择器,请改用 class 选择 ...

随机推荐

  1. ShardingSphere

    目录 1.ShardingSphere分表与分库分表 2.ShardingSphere分库分表查询 3.自定义分片算法实现range查询 4.SPI扩展机制概述 5.stand通过SPI实现range ...

  2. Yarp 与 Nginx性能大比拼不出所料它胜利了!

    Yarp 与 Nginx 性能大比拼 测试环境: Ubuntu 22.04.3 LTS (GNU/Linux 6.5.0-14-generic x86_64) Intel(R) Xeon(R) CPU ...

  3. Xcode的Search Paths配置

    在Xcode中的文件搜索路径配置有两个地方,一个是Project层的配置,一个是Target的配置. Project-Build Settings-Search Paths Target-Build ...

  4. Spring自带的这11个工具类,真香!

    前言 最近有些小伙伴,希望我分享一些好用的工具类,帮他们提升开发效率. 今天这篇文章专门跟大家一起总结一下,Spring框架本身自带的一些好用的工具类,希望对你会有所帮助. 1 Assert 很多时候 ...

  5. PHP常用类

    PHP常用类 一.分页类 <?php /** * 分页类 * 调用方式: * $p=new Page(总条数,显示页码链接数量,当前页码,每页显示条数,[链接]); * print_r($p-& ...

  6. pandas 用户数据分析

    import pandas as pd import numpy as np from matplotlib import pyplot as plt """ 第一部分: ...

  7. CF1089K King Kog's Reception 题解

    题目传送门 前置知识 线段树 解法 第一眼感觉和 luogu P1083 [NOIP2012 提高组] 借教室 很像.本题同样采用线段树维护,\(sum_{l,r}(1 \le l \le r \le ...

  8. zookeeper源码(08)请求处理及数据读写流程

    ServerCnxnFactory 用于接收客户端连接.管理客户端session.处理客户端请求. ServerCnxn抽象类 代表一个客户端连接对象: 从网络读写数据 数据编解码 将请求转发给上层组 ...

  9. el-upload使用http-request自定义上传和进度条实战

    介绍 项目中发现使用默认的el-upload上传动作发送上传请求的时候不会带上请求头,于是想通过自定义请求也就是http-request来自定义上传.实践证明这条路是通的,不过有个小问题就是原本上传的 ...

  10. 将字符串"a,b,c"以逗号分隔转换为数组并打印

    主要利用了String的split方法. package com.dylan.test; /** * @author xusucheng * @create 2017-12-22 **/ public ...