为了在 /components/InfoTotal.tsx 中显示来自 /pages/index.tsx 的数据,您可以将数据作为道具传递给 InfoTotal 组件。

首先,在 InfoTotal 组件中从 /pages/index.tsx 导入 Totals 函数:

import { Totals } from '../pages/index';

然后,将 totalsites 数据作为道具传递给 InfoTotal 组件:

<InfoTotal totalsites={totalsites} />

最后,在 InfoTotal 组件中,通过 props 访问 totalsites 数据:

export function InfoTotal({ totalsites }: { totalsites: number }) {
  return <div>网站总:{totalsites}</div>;
}
如何在 Next.js 中将 /pages/index.tsx 的数据传递给 /components/InfoTotal.tsx

原文地址: https://www.cveoy.top/t/topic/mYUi 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录