Sass map.get()不起作用.map-get()可以.是什么赋予了? [英] Sass map.get() doesn't work. map-get() does. What gives?

查看:80
本文介绍了Sass map.get()不起作用.map-get()可以.是什么赋予了?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立了一个颜色值映射表,并创建了一个简单的函数来检索它们.

I set up a map of color values and created a simple function to retrieve them.

在进行检索时,我遵循了 Sass文档,该文档指出您可以进行检索使用 map.get()函数的地图值.使用此代码或任何其他 map.function 会导致错误:没有名称空间为"map"的模块..

While doing the retrieval, I followed the Sass documentation which states that you can retrieve a map value using the map.get() function. Using this or any other map.function results in an Error: There is no module with the namespace "map"..

在检查地图模块时,我注意到了一种可行的替代语法 map-get().

Checking out the map module, I noticed an alternative syntax, map-get(), which does work.

有什么作用?我是否缺少某些东西,例如导入地图模块,以便可以这种形式使用它?

What gives? Am I missing something, like importing the map module, so that I can use it in that form?

在下面查看我的代码:

// Using npm dart `sass 1.26.11`.

$colors: ('primary': black, 'secondary': white);

// Doesn't work    
@function color($color) {
  @return map.get($colors, $color);
}

// Does work
@function color($color) {
  @return map-get($colors, $color);
}

问题:为了使 map.get()语法起作用,我需要更改什么?

Question: What do I need to change to get the map.get() syntax to work?

推荐答案

我遇到了与OP类似的问题(使用dart-sass v1.25.0),并且只有 map-get 有效, map.get 不会.

I am having a similar issue as OP (using dart-sass v1.25.0), and only map-get works, map.get doesn't.

文档在此方面似乎不太清楚,但是(

The documentation doesn't seem to be very clear on this, but the (Sass Module System: Draft 6) document on Github explains it better.

似乎 Sass正在继续使用以使用 @use 支持 @import ,以便与本机CSS更好地兼容,并且为了获得对 map.get 的访问权限,您现在必须显式导入 map模块使用 @use 关键字.

It seems like Sass is moving on to using @use in favour of @import for better compatibility with native CSS, and in order to get access to map.get you now must explicitly import the map module using the @use keyword.

@use "sass:map";

$colors: ('primary': black, 'secondary': white);

@function color($color) {
  @return map.get($colors, $color);
}

这篇关于Sass map.get()不起作用.map-get()可以.是什么赋予了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆