Mat*_*att 6 html javascript jsx next.js
在我的 Next.js 应用程序中,我收到此警告:
Warning: Extra attributes from the server: style
Run Code Online (Sandbox Code Playgroud)
我不知道这是在哪里发生的,所以没有任何代码可以显示。
小智 2
我遇到了同样的问题,结果是直接将样式添加到导致它的原因<body>中layout.tsx
...
export default function RootLayout({ children }: { children: React.ReactNode}) {
return(
<html lang="en">
<body style={{ display: "flex" }}>
...
</body>
</html>
)
}
Run Code Online (Sandbox Code Playgroud)
要解决这个问题,请创建一个单独的styles.css文件 -> 添加正文样式 -> 将其导入到layout.tsx
样式.css:
body {
display: flex;
}
Run Code Online (Sandbox Code Playgroud)
布局.tsx:
...
import "./globals.css"
export default function RootLayout({ children }: { children: React.ReactNode}) {
return(
<html lang="en">
<body>
...
</body>
</html>
)
}
Run Code Online (Sandbox Code Playgroud)
注意:这是在 Next.js 13 中测试的我不确定其他版本