发送获取请求时处理参数



我有这个请求,它是为了返回我的所有空间。

我想做一个函数来处理后端,我想传递参数";工作空间Id";。

问题是我该怎么做?

GET:{{url}}/spaces?workspaceId=60e33c7cc447c80015bdbdab

功能:

getAllSpaces: async () => {
const response = await api.get(
"spaces/:workspaceId"
).then(res=>{
console.log('values inside zustand 2: ')
console.log('response inside zustand 3: ', res);

set(state =>{
state.space = res.data;
})
console.log('response data: ', res.data)
}).catch(err =>{
console.log(err)
})
}

您没有提到您的库,这就是我使用axios的原因。它在react中非常流行

使用axios,非常容易阅读:

axios.get(this.state.url+'/spaces', {
params: {
workspaceId: this.state.workspaceId
}
}).then((res)=>{
...
});

最新更新