SCSS中的css變數定義及呼叫
阿新 • • 發佈:2022-12-08
1、定義variables.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: #ffffff; // 用於程式碼中呼叫 :export{ menuColor: $base-menu-color; menuLightColor: $base-menu-light-color; menuColorActive: $base-menu-color-active; menuBackground: $base-menu-background; menuLightBackground: $base-menu-light-background; menuLightBackgroundMy: $base-menu-light-background-my; subMenuBackground: $base-sub-menu-background; subMenuHover: $base-sub-menu-hover; sideBarWidth: $base-sidebar-width; logoTitleColor: $base-logo-title-color; logoLightTitleColor: $base-logo-light-title-color }
2、在<style>標籤中呼叫
<style lang="scss" scoped> @import "~@/assets/styles/variables.scss"; .fixed-header { position: fixed; top: 0; right: 0; z-index: 9; width: calc(100% - #{$base-sidebar-width}); transition: width 0.28s; }
.tools-wrap-hidden{
z-index: 1;
position: absolute;
left: $base-sidebar-width + 10;
top: 4em;
display: flex;
flex-direction: column;
}
</style>
3、在其他css檔案中呼叫方式
@import './variables.scss';
4、在程式碼中呼叫方式
<div :style="{ backgroundColor: settings.sideTheme === 'theme-dark' ? variables.menuBackground : variables.menuLightBackgroundMy }">
<script>
import variables from "@/assets/styles/variables.scss";
export default {
computed: {
variables() {
return variables;
},
}
}
</script>