小编Der*_*wan的帖子

Next JS v13:如何使用 @next/font 添加 google 字体的字体粗细变体

Next JS v13 之后,@next/font有助于获得最佳性能。@import在这个包存在之前,在我在全局 CSS 中使用 CDN google 字体之前

/* path: ./styles/global.css */
@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700;800;900&display=swap");
Run Code Online (Sandbox Code Playgroud)

现在我想迁移并使用@next/font@13.0.2

/* path: ./pages/_app.tsx */
import { Poppins } from "@next/font/google";

const poppins = Poppins({
  weight: "800", // I want this font-weight has 400,500,600,700,800,900
});

function MyApp({ Component, pageProps }) {
  return (
    <>
      <style jsx global>{`
        html {
          font-family: ${poppins.style.fontFamily};
        }
      `}</style>

      <Component {...pageProps} />
    </>
  );
}

Run Code Online (Sandbox Code Playgroud)

我一直尝试使用数组来代替:

const poppins = Poppins({
  weight: ["400", "500", "600", "700", "800", …
Run Code Online (Sandbox Code Playgroud)

javascript fonts reactjs next.js

9
推荐指数
1
解决办法
2万
查看次数

标签 统计

fonts ×1

javascript ×1

next.js ×1

reactjs ×1