小编Mar*_*iya的帖子

有没有更好的方法将类放入 next.js 中的 html 和 body 标签中?

我正在使用 Next.js 和 Tailwind,为了使某些元素正确显示,我需要将一些样式类放入<html>和中<body>

我对我的MyApp

function MyApp({ Component, pageProps}: AppProps) {
  useEffect(() => {
    document.querySelector("html").classList.add("h-full");
    document.querySelector("body").classList.add("h-full");
    document.querySelector("#__next").classList.add("h-full");
  });

  return (
      <Component {...pageProps} />
  )
}
Run Code Online (Sandbox Code Playgroud)

这是可行的......但我想知道是否还有其他方法,或更优雅的解决方案。

reactjs next.js tailwind-css

6
推荐指数
1
解决办法
4727
查看次数

标签 统计

next.js ×1

reactjs ×1

tailwind-css ×1