0

目前我尝试以更少的成本构建 mixins,但它似乎比预期的要复杂。例如,我尝试构建一个 if 条件,我的标题如下所示:

.ifClauses(
   @checkParam,
   @conditions:{
    isnumber(@checkParam),
    ispercentage(@checkParam),
    ispixel(@checkParam)
   },
   @thens:{
    .first(){height:@checkParam * 1px;},
    .second(){height:@checkParam;},
    .third(){height:@checkParam;}
   }
)

我知道数组的定义如下:

@array: first,second,third;

.

也许我可以将其用作一个对象,可以这么说,当参数用逗号分隔时,如何将数组写入 mixins 参数?

4

1 回答 1

0

我是这样解决的:

.height(@param: @_tablet_slider_-height){

      @active : false;

      & when(isnumber(@param)){
        height: @param * 1px;
        @active: true;
      }
      & when(isunit(@param)){
        height: @param;
        @active: true;
      }

      & when(ispixel(@param)){
        height: @param;
        @active: true;
      }

      & when(isem(@param)){
        height: @param;
        @active: true;
      }
      & when(ispercentage(@param)){
        height: @param;
        @active: true;
      }

      & when(@active = false){

        &:before{
          content:"Error in parsing less"
        }

      }  
}
于 2015-07-01T13:16:57.817 回答