我从sass开始,正在尝试使用变量导入文件。
看起来像这样
// _variables.scss
$blue: #0D6EFF;
$red: #FB2B37;
$black: #272727;
$green: #31E3A1;
$lightgrey: rgba(172, 179, 186, 0.5);
// style.scss
@use "variables";
html, body{
height: 100%;
margin: 0;
position: relative;
color: $blue;
font-size: 18px;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
当我编译时,出现“未定义的变量”,并在style.css中出现“ @use'variables'”,但如果使用@import,则一切正常。我知道我可以使用导入,但是在Sass网站上,他们建议使用“ @use”,所以您能帮我解决该错误并了解为什么它不起作用吗?
根据文档,sass在使用时会添加一个隐式名称空间@use
。
因此,如果您在文件前使用下划线写文件,例如_variables.scss
:
$blue: #0D6EFF;
$red: #FB2B37;
$black: #272727;
$green: #31E3A1;
$lightgrey: rgba(172, 179, 186, 0.5);
您将可以通过variables
名称空间使用以下变量:
@use "variables";
html, body{
height: 100%;
color: variables.$blue;
...
如果需要其他名称空间名称,请使用as
:
@use "variables" as myVariables;
html, body{
height: 100%;
color: myVariables.$blue;
...
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句