【问题标题】:LESS merge variable names and get valueLESS 合并变量名并获取值
【发布时间】:2014-01-15 21:40:05
【问题描述】:

我想创建一个 mixin,通过合并参数来返回命名空间变量的值。

查看:

@namespace_thing: "some value";
@namespace_otherthing: "some other value";

@othernamespace_thing: "another value";
@othernamespace_otherthing: "again other value";

混合:

.monster(@namespace,@var){
 @tmp: ~"@{namespace}"+"_"+@{var};

 content: @tmp // That's what I just dont know.

}

#TESTSELECTOR{

.monster(namespace,thing); // would return 

    content: "some value";

}

【问题讨论】:

    标签: variables merge namespaces less mixins


    【解决方案1】:

    最简单的方法是使用variable name references

    @namespace_thing: "some value";
    
    .monster(@namespace, @var) {
        @ref: '@{namespace}_@{var}';
        content: @@ref;
    }
    
    usage {
        .monster(namespace, thing);
    }
    

    如果您需要返回一个值而不是将其分配给预定义的属性,另请参阅mixins as functions

    【讨论】:

    • 感谢@seven-phases-max!这就是我要找的:)
    猜你喜欢
    • 2013-11-05
    • 1970-01-01
    • 2014-10-28
    • 1970-01-01
    • 1970-01-01
    • 2018-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多