3

是否可以使用变量作为键来定义地图?

示例代码

$types: (
        'INPUT': 1,
        'SELECT': 2,
        'BUTTON': 3,
);

$colors: (
        $types['INPUT'] : #f44336,
        $types['SELECT']: #2196f3,
        $types['BUTTON']: #9c27b0,
);
4

1 回答 1

3

我发现了怎么做

@function type($key) {
  @return map-get($types, $key);
}

$colors: (
        type('INPUT'): #f44336,
        type('SELECT'): #2196f3,
        type('BUTTON'): #9c27b0,
}
于 2018-11-01T12:16:04.850 回答