当前位置: 首页 > news >正文

前端新手Vue3+Vite+Ts+Pinia+Sass项目指北系列文章 —— 第六章 样式格式化 (Sass配置)

系列文章目录(点击查看)


文章目录

  • 系列文章目录(点击查看)
  • 前言
  • 一、安装
  • 二、使用
  • 三、安装公共样式
  • 四、入口文件配置
  • 五、测试
  • 总结


前言

本篇涉及安装 sass,并且配置项目 sass 的初始化样式。


一、安装

根据前面的项目配置,安装sass就非常的简单

yarn add sass

在这里插入图片描述

package.json 中检查是否安装成功
在这里插入图片描述

二、使用

src 文件下新增 styles 文件夹

增加 variables.module.scss 文件

// base color
$blue: #324157;
$light-blue: #3a71a8;
$red: #c03639;
$pink: #e65d6e;
$green: #30b08f;
$tiffany: #4ab7bd;
$yellow: #fec171;
$panGreen: #30b08f;// 默认菜单主题风格
$base-menu-color: #bfcbd9;
$base-menu-color-active: #f4f4f5;
$base-menu-background: #304156;
$base-logo-title-color: #fff;$base-menu-light-color: #697280;
$base-menu-light-color-active: #697280;
$base-menu-light-background: #fff;
$base-logo-light-title-color: #001529;$base-sub-menu-background: #1f2d3d;
$base-sub-menu-hover: #001528;$base-sub-menu-light-background: #fff;
$base-sub-menu-light-active: #f2f3f5;
$base-sub-menu-light-hover: #f7f9fa;$--color-primary: #409eff;
$--color-success: #67c23a;
$--color-warning: #e6a23c;
$--color-danger: #f56c6c;
$--color-info: #909399;$base-sidebar-width: 260px;

增加 transition.scss 文件

// global transition css/* fade */
.fade-enter-active,
.fade-leave-active {transition: opacity 0.28s;
}.fade-enter,
.fade-leave-active {opacity: 0;
}/* fade-transform */
.fade-transform-leave-active,
.fade-transform-enter-active {transition: all 0.5s;
}.fade-transform-enter {opacity: 0;transform: translateX(-30px);
}.fade-transform-leave-to {opacity: 0;transform: translateX(30px);
}/* breadcrumb transition */
.breadcrumb-enter-active,
.breadcrumb-leave-active {transition: all 0.5s;
}.breadcrumb-enter,
.breadcrumb-leave-active {opacity: 0;transform: translateX(20px);
}.breadcrumb-move {transition: all 0.5s;
}.breadcrumb-leave-active {position: absolute;
}

增加 element.scss 文件

#app {& .theme-dark .nest-menu .el-sub-menu > .el-sub-menu__title,& .theme-dark .el-sub-menu .el-menu-item {background-color: $base-sub-menu-background !important;&:hover {background-color: $base-sub-menu-hover !important;}}.el-button.is-text {padding-right: 0;padding-left: 0;}.el-table {margin: 10px 0;}.scp-table .el-table {font-size: 12px;--el-table-border: transparent;.el-table__inner-wrapper::before {display: none;}.el-table__header-wrapper {border-top: 1px solid #f2f3f5;th {height: 50px !important;font-size: 12px !important;color: #909399 !important;background: #fff !important;font-weight: normal !important;}}.el-table__body-wrapper {font-weight: bold;overflow: hidden;border: 1px solid #f2f3f5;border-bottom: 0;border-radius: 10px;}.el-table__cell {padding: 8px 0;.cell {/* height: auto; */line-height: 30px;}/* background: #f4f9fa; */}.el-table__row--striped .el-table__cell {/* background: #f2f3f5; */}.el-empty__description p {font-weight: normal;font-size: 12px;}}.el-dialog__body {padding-top: 15px;padding-bottom: 15px;}.el-input-number {width: 100%;.el-input__inner {text-align: left;}}.el-drawer__header {margin-bottom: 0;}
}

增加 index.scss 文件

@import './variables.module';
@import './transition';
@import './element';:root {font-size: 14px;font-weight: 400;background-color: #fff;
}html,
body,
#app {width: 100%;height: 100%;
}a {text-decoration: none;
}.flex {display: flex;
}.flex-sb {display: flex;justify-content: space-between;
}.flex-c {display: flex;justify-content: center;
}.flex-sa {display: flex;justify-content: space-around;
}.flex-end {display: flex;justify-content: flex-end;
}.flex-align {display: flex;align-items: center;
}.flex-wrap {display: flex;flex-wrap: wrap;
}.flex-column {display: flex;flex-direction: column;
}.flex-column-sb {display: flex;flex-direction: column;justify-content: space-between;
}.flex-column-align-center {display: flex;flex-direction: column;justify-content: center;align-items: center;
}.flex-align-sb {display: flex;justify-content: space-between;align-items: center;
}.flex-align-sa {display: flex;justify-content: space-around;align-items: center;
}.flex-column-sa {display: flex;flex-direction: column;justify-content: space-around;
}.flex-align-ai {display: flex;align-items: center;
}.flex-center {display: flex;justify-content: center;align-items: center;
}.flex-sba {display: flex;justify-content: space-between;align-items: center;
}

三、安装公共样式

yarn add normalize.css

在这里插入图片描述

四、入口文件配置

main.ts 文件中

import { createApp } from 'vue'
import App from './App.vue'import 'normalize.css' # 新增
import './styles/index.scss' # 新增
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'const app = createApp(App)app.use(ElementPlus)
app.mount('#app')

五、测试

修改 App.vue 文件代码

<template><div style="height: 100vh" class="flex-c flex-align"><el-row class="mb-4"><el-button>Default</el-button><el-button type="primary">Primary</el-button><el-button type="success">Success</el-button><el-button type="info">Info</el-button><el-button type="warning">Warning</el-button><el-button type="danger">Danger</el-button></el-row></div>
</template><script setup lang="ts"></script><style scoped></style>

在这里插入图片描述


总结

本文主要介绍了如何安装 sass 并在 package.json 中确认安装成功,创建了 styles 文件夹,并添加了 variables.module.scsstransition.scsselement.scssindex.scss 文件,安装了 normalize.css 并在入口文件 main.ts 中引入,修改了 App.vue 文件以测试样式应用。上文中的配置代码可在 github 仓库中直接 copy,仓库路径:https://github.com/SmallTeddy/testing-web。

相关文章:

  • AI一点通:卷积神经网络的输出节点大小如何计算?全连接层必要输入大小如何设置
  • 数据库知识点总结(一)
  • Go——二、变量和数据类型
  • C#面试题3
  • 马养殖场建设VR模拟实训教学平台具有灵活性和复用性
  • ES6 — ES14 新特性
  • Python算法——树的拓扑排序
  • python将模块进行打包
  • 主流开源大语言模型的微调方法
  • centeros7系统安装指定版本的mongodb数据库
  • 『Linux升级路』基础开发工具——gcc/g++篇
  • 【Python大数据笔记_day11_Hadoop进阶之MR和YARNZooKeeper】
  • 【docker】安装redis和mysql生产实战
  • 聚观早报 |一加12正式开启预订;OPPO Reno11系列卖点
  • 【中间件】服务化中间件理论intro
  • [nginx文档翻译系列] 控制nginx
  • 【EOS】Cleos基础
  • 【编码】-360实习笔试编程题(二)-2016.03.29
  • CentOS7简单部署NFS
  • JAVA之继承和多态
  • magento 货币换算
  • mysql 5.6 原生Online DDL解析
  • node入门
  • session共享问题解决方案
  • Spring Cloud Feign的两种使用姿势
  • 得到一个数组中任意X个元素的所有组合 即C(n,m)
  • 分享几个不错的工具
  • 缓存与缓冲
  • 力扣(LeetCode)56
  • 漂亮刷新控件-iOS
  • 人脸识别最新开发经验demo
  • 通过获取异步加载JS文件进度实现一个canvas环形loading图
  • 微服务框架lagom
  • 学习笔记:对象,原型和继承(1)
  • Hibernate主键生成策略及选择
  • ionic异常记录
  • 蚂蚁金服CTO程立:真正的技术革命才刚刚开始
  • ​如何在iOS手机上查看应用日志
  • #经典论文 异质山坡的物理模型 2 有效导水率
  • %@ page import=%的用法
  • (12)Linux 常见的三种进程状态
  • (超详细)语音信号处理之特征提取
  • (附源码)apringboot计算机专业大学生就业指南 毕业设计061355
  • (附源码)计算机毕业设计SSM智能化管理的仓库管理
  • (考研湖科大教书匠计算机网络)第一章概述-第五节1:计算机网络体系结构之分层思想和举例
  • (强烈推荐)移动端音视频从零到上手(下)
  • .apk文件,IIS不支持下载解决
  • .form文件_一篇文章学会文件上传
  • .Net Core/.Net6/.Net8 ,启动配置/Program.cs 配置
  • .Net mvc总结
  • .net 验证控件和javaScript的冲突问题
  • .NET框架设计—常被忽视的C#设计技巧
  • .NET设计模式(11):组合模式(Composite Pattern)
  • .NET项目中存在多个web.config文件时的加载顺序
  • .sys文件乱码_python vscode输出乱码