gpt4 book ai didi

css - Sass Rails 不支持映射语法(对象变量)

转载 作者:行者123 更新时间:2023-11-28 15:16:09 25 4
gpt4 key购买 nike

尝试使用 Sass Maps 时出现以下错误(看起来像对象变量):

Invalid CSS after "  primary": expected ")", was ": #3097D1,"
(in /Users/.../app/assets/stylesheets/new_design.scss:19)

我使用以下最小示例重现了错误:

$theme-colors: (
primary: #3097D1,
secondary: black
);

@each $key, $val in $theme-colors {
.foo.#{$key} {
color: $val;
}
}

预期:

.foo.primary {
color: #3097D1;
}

.foo.secondary {
color: black;
}

但是得到提到的错误。

sass-rails, ~> 5.0.0 好像是根据Gemfile安装的:

gem 'sass-rails',   '~> 5.0.0' 

我假设加载了一个最新的 sass 版本,它应该支持对象变量。

我感觉我的当前版本无法识别这种语法。

如何确保我拥有正确的 sass 版本?我还需要做些什么才能成功编译此语法吗?


bundle show sass-rails 显示 5.0.6,这似乎是最近的。

最佳答案

正如评论中所讨论的那样,有一个 stackoverflow关于 map sass 语法的类似问题的讨论

讨论引用Github Issue 1088

我引用

There's a number of issues with the indented syntax, and Sass maintainers aren't going to fix them. :( They say, the .sass parser is weird and hard to refactor.

I find Sass syntax to be quicker to type and easier to read. It is deprived of the visual noise:

indented_vs_bracketed

It's also much easier to do copy-pasting.

So Sass maintainers, PLEASE don't let the indented syntax fall behind!

也许通过在讨论中深入挖掘,我们将能够找到解决方案。现在我引用帖子所有者的解决方案 Ionică Bizău :

wrapping the values between quotes, saving, reloading in browser without any errors, and then removing the quotes back and reloading the page in browser solved the problem. Maybe it was something cached somewhere... but I can't understand where. I didn't restart rake or ran any bundle command... Thanks! :)

关于css - Sass Rails 不支持映射语法(对象变量),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47177158/

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