·

重新回去看了一下官方文档,原来是给了解决方案的,是我菜了,文档都看不明白 joy

利用getStaticProps 返回值 notFound属性,加个if校验,数据库若没对应数据的话可以不生成静态文件

export async function getStaticProps(context) {
  const res = await fetch('http://localhost:3030/api/msq/search?id='+context.params.aid)
  const result = await res.json()
  //判断后端数据是否存在,不存在不生产页面
  if (!result.success) {
    return {
      notFound:true,
      revalidate: 10,
    }
  } 
  return {
    props: {
      datas:result.data,
    },
    revalidate: 10,
  }
}