小编Man*_*son的帖子

更改深色模式(类)顺风的图像

当我切换到黑暗模式时,我想更改我的徽标图像(我在顺风上使用类)。有机会成功吗?

这是我用来更改主题的钩子:

const useTheme = () => {
  const [theme, setTheme] = useState(localStorage.theme);
  const nextTheme = theme === "light" ? "dark" : "light";

  useEffect(() => {
    const rootElement = window.document.documentElement;
    rootElement.classList.remove(nextTheme);
    rootElement.classList.add(theme);
    localStorage.setItem("theme", theme);
  }, [theme, nextTheme]);

  return [nextTheme, setTheme];
};
Run Code Online (Sandbox Code Playgroud)

这是我想要改变的形象(如果有帮助的话):

<div className="flex flex-col">
  <Link
    to="/"
    className="flex px-5 gap-2 my-6 pt-1 w-190 items-center"
    onClick={handleCloseSideBar}
  >
    <img src="/img/logo.png" alt="logo" className="w-full" />
  </Link>
</div>;
Run Code Online (Sandbox Code Playgroud)

tailwind-css darkmode

4
推荐指数
1
解决办法
1905
查看次数

标签 统计

darkmode ×1

tailwind-css ×1