安装sass

npm install sass -D

安装normalize.css初始化样式

npm install --save normalize.css

新建style目录保存各种样式

image.png

variables.scss配置全局变量

  1. //主题色
  2. $color-primary: #409EFF;
  3. //复制信息提示色
  4. $color-success: #67C23A;
  5. $color-warning: #E6A23C;
  6. $color-danger: #F56C6C;
  7. $color-info: #909399;
  8. //文本颜色
  9. $color-text-primary: #303133;
  10. $color-text-regular: #606266;
  11. $color-text-secondary: #909399;
  12. $color-text-placeholder: #C0C4CC;
  13. //边框颜色
  14. $color-border-base: #DCDFE6;
  15. $color-border-light: #E4E7ED;
  16. $color-border-lighter: #EBEEF5;
  17. $color-border-extra-light: #F2F6FC;
  18. //背景颜色
  19. $color-background-white: #FFFFFF;
  20. $color-background-black: #000000;
  21. $color-background-base: #F5F7FA;
  22. //字体大小
  23. $size-font-h1: 36px;
  24. $size-font-h2: 24px;

index.scss中组织这些样式,并编写全局样式

  1. @import "./normalize.css";
  2. @import "./element-ui.scss";
  3. @import "./transition.scss";
  4. @import "./variables.scss";
  5. #app{
  6. color: $color-primary;
  7. }

main.js中引入index.scss

  1. import {createApp} from 'vue'
  2. import App from './App.vue'
  3. import '/style/index.scss'
  4. import {router} from './router'
  5. import store from './store'
  6. const app = createApp(App)
  7. app.use(router)
  8. app.use(store)
  9. app.mount('#app')

vue代码使用变量

  1. <style lang="scss">
  2. @import "~@/assets/style/variable";
  3. #app {
  4. color: $color-primary;
  5. text-align: center;
  6. }
  7. #nav {
  8. padding: 30px;
  9. a {
  10. font-weight: bold;
  11. color: #2c3e50;
  12. &.router-link-exact-active {
  13. color: #42b983;
  14. }
  15. }
  16. }
  17. </style>