初步学习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
浙公网安备 33010602011771号