简体   繁体   English

从@include调用时未传递Sass Mixin值

[英]Sass Mixin value is not getting passed on calling from @include

I have couple of partials(say _one.scss and _two.scss) which am calling into a SASS. 我有几个局部函数(例如_one.scss和_two.scss)正在调用SASS。 _one.scss has following code _one.scss具有以下代码

@mixin wire($num) {
 .parts-field {
  height: 100%;
width: calc(100% * (1/$num) - 10px - 1px);
}

And in _two.scss has .mytry { @include wire(3); } 并且在_two.scss中具有.mytry { @include wire(3); } .mytry { @include wire(3); }

In my main.scss am doing the following 在我的main.scss中,正在执行以下操作

@import "../../base/_one.scss"; 
@import "_two.scss";

When I check main.css , it shows the following: 当我检查main.css时 ,它显示以下内容:

.mytry .parts{
height: 100%;
width: calc(100% * (1/$num) - 10px - 1px);
}

Even though am saying @include wire(3) , I believe the 3 is not getting passed. 即使我说@include wire(3) ,我也相信3没有通过。 Styles are not applying on the HTML either. 样式也不适用于HTML。 Is there something fundamentally wrong am doing with param passing to mixins? 将参数传递给mixins根本上有错吗?

You need to use string interpolation, ie replace $num with #{$num} : 您需要使用字符串插值,即将$num替换$num #{$num}

@mixin wire($num) {
  .parts-field {
    height: 100%;
    width: calc(100% * (1/#{$num}) - 10px - 1px);
  }
}

The reason why this is needed because SASS will treat (...) as a calculation that has to be evaluated during compilation, and it does not know that calc(...) should be interpreted as a string and not a mathematical expression. 之所以需要这样做,是因为SASS会将(...)视为必须在编译期间求值的计算,并且它不知道calc(...)应该解释为字符串而不是数学表达式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM