简体   繁体   English

较少的编译变量和其他变量名错误

[英]Less compiling variable with other variable name error

I have a problem with variables declared with other variable name. 我用其他变量名声明的变量有问题。 In the below mixin I have a variable declared with other variable name like: 在下面的mixin中,我有一个用其他变量名声明的变量,例如:

.label-color(@color) {
  @label-class:~"label-@{color}";
  @badge-class:~"badge-@{color}";
    @label-color:@@label-class;


 .@{label-class}, .@{badge-class} {
    background-color:@label-color !important;
 }  
}


.label-arrow(@color) {
   @label-class:~"label-@{color}";
   @label-color:@@label-class;

  .@{label-class}{
    &.arrowed:before {
        border-right-color:@label-color;
    }
    &.arrowed-in:before {
        border-color:@label-color;
    }
    &.arrowed-right:after {
        border-left-color:@label-color;
    }
    &.arrowed-in-right:after {
        border-color:@label-color;
    }
  }
}

Unfortunately my compiler does not recognize this kind of @label-color:@@label-class; 不幸的是,我的编译器无法识别这种@label-color:@@label-class; and pull out error at this line. 并在这一行拉出错误。 What modification should I do in order to compile well this part of my less. 为了更好地编译我的这部分内容,我应该做什么修改。

ty. TY。

Lessj4 seems to support variable referencing only by quoted string values so you have to split concatenation and escaping there (ie do not use ~"..." for @@ variables). Lessj4似乎仅支持用引号引起来的字符串引用变量,因此您必须在此处拆分并转义(即, @@变量不要使用~"..." )。 Eg the first mixin would look like this then: 例如,第一个mixin如下所示:

.label-color(@color) {
    @label-color_: "label-@{color}";
    @label-color: @@label-color_;

    .label-@{color}, .badge-@{color} {
        background-color: @label-color !important;
    }  
}

Same changes for the second mixin. 第二个mixin的更改相同。 (Assuming both mixins are invoked like .label-color(~"red"); or like .label-color(potato); ). (假定两个mixin都像.label-color(~"red");或像.label-color(potato);一样被调用)。

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

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