1

我正在尝试使用一种混合来计算另一个包含我的基本字体样式的基线高度。每次我尝试编译时,都会出现错误。

这是一个例子。

.lineHeight(@sizeValue){
@remValue: @sizeValue;
@pxValue: (@sizeValue * 10);
line-height: ~"@{pxValue}px";
line-height: ~"@{remValue}rem";
}

.baseFont(@weight: normal, @size: 14px, @lineHeight: (.lineHeight(2.1)) {
font-family: @fontFamily;
font-size: @size;
font-weight: @weight;
line-height: @lineHeight;
}

The error is: TypeError: Cannot call method 'charAt' of undefined at getLocation (/Applications/CodeKit.app/Contents/Resources/engines/less/lib/less/parser.js:212:34) at new LessError (/Applications/CodeKit.app/Contents/Resources/engines/less/lib/less/parser.js:221:19) at Object.toCSS (/Applications/CodeKit.app/Contents/Resources/engines/less/lib/less/parser.js:385:31) at /Applications/CodeKit.app/Contents/Resources/engines/less/bin/lessc:107:28 at /Applications/CodeKit.app/Contents/Resources/engines/less/lib/less/parser.js:434:40 at /Applications/CodeKit.app/Contents/Resources/engines/less/lib/less/parser.js:94:48 at /Applications/CodeKit.app/Contents/Resources/engines/less/lib/less/index.js:116:17 at /Applications/CodeKit.app/Contents/Resources/engines/less/lib/less/parser.js:434:40 at /Applications/CodeKit.app/Contents/Resources/engines/less/lib/less/parser.js:94:48 at /Applications/CodeKit.app/Contents/Resources/engines/less/lib/less/index.js:116:17

4

1 回答 1

0

从另一个参数列表中调用一个 mixin 是没有意义的(除了(在调用 mixin 之前你有一个额外的方面)。

这是我对 mixin 继承的尝试,它适用于您的情况,但不是我见过的最优雅的 LESS。重量和尺寸的默认值也需要在两个地方重复:

.lineHeight(@sizeValue){
    @remValue: @sizeValue;
    @pxValue: (@sizeValue * 10);
    line-height: ~"@{pxValue}px";
    line-height: ~"@{remValue}rem";
}

// Shared by both versions of baseFont, never used directly
.commonBaseFont(@weight, @size) {
    font-family: @fontFamily;
    font-size: @size;
    font-weight: @weight;
}

// baseFont called without lineHeight argument
.baseFont(@weight: normal, @size: 14px){
    .commonBaseFont(@weight, @size);
    .lineHeight(2.1)
}

// baseFont called with lineHeight argument
.baseFont(@weight: normal, @size: 14px, @lineHeight) {
    .commonBaseFont(@weight, @size);
    line-height: @lineHeight;
}
于 2012-06-08T04:43:51.930 回答