初步学习next.js-4-在getInitialProps中用axios获取数据

yarn add axios
import axios from 'axios'
const Page = ({ stars }) =>
  <div>
    Next stars: {stars}
  </div>

Page.getInitialProps = async ({ req }) => {
  const res = await fetch('https://api.github.com/repos/zeit/next.js')
  const json = await res.json()
  return { stars: json.stargazers_count }
}

export default Page

 

posted on 2020-06-17 13:39  秃了头也不退休  阅读(957)  评论(0编辑  收藏  举报

导航