[英]How to get colour values from tailwind config file
我想从配置文件中访问“accent”颜色的值,以便我可以将其分配给新颜色。 我尝试过danger: theme('colors.accent')
但我收到此错误> theme is not defined
。 我想避免再次对十六进制颜色代码进行硬编码。 有没有办法轻松做到这一点?
tailwind.config.js
colors: {
accent: '#57A0D7',
accentlight: '#88BCE2',
accentdark: '#4B8CBD',
accentdarker: '#4682B0',
danger: theme(colors.accent),
肯定的事。 只需设置要出现在module.exports
之外的多个位置的module.exports
,您就可以在任何地方将其用作变量,因为配置文件只是一个 js 文件。
const accent = '#57A0D7';
module.exports = {
theme: {
colors: {
accent,
accentlight: '#88BCE2',
accentdark: '#4B8CBD',
accentdarker: '#4682B0',
danger: accent
}
}
}
尝试使用函数
colors: {
accent: '#57A0D7',
accentlight: '#88BCE2',
accentdark: '#4B8CBD',
accentdarker: '#4682B0',
danger: theme => theme('colors.accent'),
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.