更改时尾风颜色未显示
我得到了一个阵列,其颜色已经在tail默认的调色板中定义了,如下所示,
colors: ["red-600", "blue-600", "pink-600", "black", "white", "yellow-600"]
我在数组上映射了,以产生带有阵列中定义的背景颜色的小盒子。
{colors.map((col, i) => (
<button
className="cursor-pointer"
key={i}
>
<div
className={`mt-3 border-2 border-solid border-black bg-${col} w-8 h-8`}
>
我的问题是,如果我更改数组中的任何颜色(例如将红色-600更改为红色900),尽管这两种颜色都在默认的调色板
这里有可能出错?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我曾经有一个问题,同时尝试了类似于您当前尝试的东西……我意识到您不能部分将尾风值设置为变量,而是如果您要去为其使用变量。
示例:
I at one point had this issue while attempting something very similar to what you're currently trying... I realized that you can't set a Tailwind value partially as a variable, rather it must be the entire value if you're going to use a variable for it.
Example:
首先,您应该将颜色数组设置为
state
,当此数组更改时,该内容使该组件会重新渲染。第二,如果仅在内部订购
颜色数组
更改,则不会强迫此组件重新渲染以读取状态更改,因此您应添加另一个状态来强制组件RE - 像这样的胶片[forcechangecolor,setforcechangecolor] = usestate(0)
:First, you should set colors array as a
state
, that thing make this component will re-render when this array change.Second, if only order inside
colors array
change, it don't force this component re-render to read your state change, so you should add another state to force component re-render like[forceChangeColor, setForceChangeColor] = useState(0)
: