“undefined”getServerSideProps在nextjs中不工作[已关闭]

arknldoa  于 2023-04-05  发布在  其他
关注(0)|答案(1)|浏览(157)

已关闭。此问题需要details or clarity。当前不接受答案。
**想要改进此问题?**添加详细信息并通过editing this post阐明问题。

4小时前关门了。
Improve this question

import SearchHeader from '@/Components/Search/SearchHeader'
import React from 'react'
export async function getServerSideProps(context) {
  const data = await fetch('https://www.googleapis.com/customsearch/v1?key=AIzaSyAJ_TRxLePr0fo7IPd1mTWyUggQZ-AQ5qk&cx=561f6a3ff44b4403e&q=graphketing').then((res) => res.json());
  return {
    props: {
      result: data  
    }
  }
}

export default function page({result}) {
  console.log(result, "result")
  return (

      <SearchHeader />

  )
}

hkmswyz6

hkmswyz61#

我想你也必须等待json:

export async function getServerSideProps(context) {
  const res = await fetch('https://www.googleapis.com/customsearch/v1?key=AIzaSyAJ_TRxLePr0fo7IPd1mTWyUggQZ-AQ5qk&cx=561f6a3ff44b4403e&q=graphketing');
  let data = await res.json();
  return {
    props: {
      result: data  
    }
  }
}

相关问题