0

如何在getServerSideProps. 我将所有结果发送到查询参数:

const filtersUsers = (changedValues, allValues) => {
    router.push({
        query : { ...allValues },
    })
}

在我的 URL 中,当我开始过滤时,我得到了这个结果:http://127.0.0.1:8082/users?lastname=lastnameFilter&firstname=firstnameFilter&email=&city=&zipcode=

export async function getServerSideProps(context) {
const res = await fetch(`http://my-project-api:8081/api/users/`)
console.log(res)
const users = await res.json()

if (!users) {
  return {
    notFound: true,
  }
}

return {
  props: {users},
}

}

如何仅将查询应用于具有已填写字段的项目并使用已填写字段更新我的 url,以及如何使用它context.query以便它自动知道要在我的表中查找哪个字段?

我已经创建了一个 API 工厂,我可以做到。

await api.getUsers(params)

结果:请求 URL: http: //127.0.0.1 :8081/api/users/?lastname=lastnameTest&firstname=firstnameTest

在参数中,我有过滤器的所有字段。我搜索如何使用getServerSideProps做到这一点

4

0 回答 0