可以通过将数据作为props传递给InfoTotal组件,在InfoTotal组件中使用props来获取数据并进行渲染。

在/pages/index.tsx中,可以这样传递数据:

import InfoTotal from '../components/InfoTotal';

function HomePage() {
  const totalsites = 10;
  return (
    <div>
      <InfoTotal totalsites={totalsites} />
    </div>
  );
}

export default HomePage;

在/components/InfoTotal.tsx中,可以这样获取并渲染数据:

function InfoTotal({ totalsites }: { totalsites: number }) {
  return (
    <div>
      <p>网站总:{totalsites}</p>
    </div>
  );
}

export default InfoTotal;
export function Totals totalsites totalsites number; const totals = totalsites; consolelog网站总:$totals; return totals Nextjs pagesindextsx 里面的数据怎么输出到 componentsInfoTotaltsx里

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

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