gpt4 book ai didi

css - 为什么我会收到语法错误 : SassError: expected "{"?

转载 作者:行者123 更新时间:2023-12-03 23:40:57 25 4
gpt4 key购买 nike

sass 给出的例子 map.set documentation不起作用,这是为什么?

@use "sass:map";

$font-weights: (
'regular': 400,
'medium': 500,
'bold': 700
);

map.set($font-weights, 'extra-bold', 900);
// ("regular": 400, "medium": 500, "bold": 700, "extra-bold": 900)
map.set($font-weights, 'bold', 900);
// ("regular": 400, "medium": 500, "bold": 900)
我的 sass版本是 1.32.5 .
整个错误信息:
Syntax Error: SassError: expected "{".

9 │ map.set($font-weights, 'extra-bold', 900);
│ ^

src\assets\styles\variables.scss 9:42 @import
src\assets\styles\main.scss 4:9 root stylesheet
我希望 map 的设置不会引发错误。

最佳答案

问题 1 (如果您使用的是 map.set ,请跳到问题 2)
实际上,我正在使用 map-set一直以来,我都在想 map-setmap.set 相同,原来不是。
在 Sass 的文档中 Built-In Modules :

Before the Sass module system was introduced, all Sass functions were globally available at all times. Many functions still have global aliases (these are listed in their documentation). The Sass team discourages their use and will eventually deprecate them, but for now, they remain available for compatibility with older Sass versions and with LibSass (which doesn’t support the module system yet).


map.set 没有全局 map-set喜欢 map.merge 确实( map-merge )。
问题2
另外,我还以为 map.set就像 JavaScript 的 Map.prototype.set() ,您可以通过它设置 map ,如 map.set(key, value)不将其分配给变量将起作用。在 Sass 中,我必须这样做:
@use "sass:map";

$map: ();
$map: map.set($map, key, value);
为什么@debug “对我不起作用”
大多数情况下,我在 vue-cli 下使用 Sass环境。 Sass的 @debug语法“从来没有”在视觉上有任何输出,结果它们实际上是输出的,我只需要向上滚动一点:
enter image description here

关于css - 为什么我会收到语法错误 : SassError: expected "{"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65911728/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com