To display the data from /pages/index.tsx in /components/InfoTotal.tsx, you can pass the data as a prop to the InfoTotal component.

First, import the Totals function from /pages/index.tsx in the InfoTotal component:

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

Then, pass the totalsites data as a prop to the InfoTotal component:

<InfoTotal totalsites={totalsites} />

Finally, in the InfoTotal component, access the totalsites data through props:

export function InfoTotal({ totalsites }: { totalsites: number }) {
  return <div>网站总:{totalsites}</div>;
}
export function Totals totalsites totalsites number; const totals = totalsites; consolelog网站总:$totals; return totals Nextjs pagesindextsx 里面的数据在 componentsInfoTotaltsx 里显示出来

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

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