如何从地图中获取值?
How to fetch a value from a map?
如何从下面的 $themes 地图中获取 'theme'?
$themes: (
default: (
theme: blue,
)
);
我尝试使用下面的地图与单个 child 并且它适用于 map-get()
SCSS
$default: (
theme: red,
);
@function fetchColor($issuer, $key) {
@return map-get($issuer, $key);
}
.navbar-brand {
background : fetchColor($default, theme);
}
Result
.navbar-brand {
background: red;
}
如何从“$themes”地图中获取相同的内容?
您可以使用解决方案 described by css-tricks.com:
$themes: (
default: (
theme: blue,
)
);
@function fetchColor($map, $keys...) {
@each $key in $keys {
$map: map-get($map, $key);
}
@return $map;
}
.navbar-brand {
background: fetchColor($themes, default, theme);
}
如何从下面的 $themes 地图中获取 'theme'?
$themes: (
default: (
theme: blue,
)
);
我尝试使用下面的地图与单个 child 并且它适用于 map-get()
SCSS
$default: (
theme: red,
);
@function fetchColor($issuer, $key) {
@return map-get($issuer, $key);
}
.navbar-brand {
background : fetchColor($default, theme);
}
Result
.navbar-brand {
background: red;
}
如何从“$themes”地图中获取相同的内容?
您可以使用解决方案 described by css-tricks.com:
$themes: (
default: (
theme: blue,
)
);
@function fetchColor($map, $keys...) {
@each $key in $keys {
$map: map-get($map, $key);
}
@return $map;
}
.navbar-brand {
background: fetchColor($themes, default, theme);
}