我在简单的反应待办事项应用程序中工作。我想搜索我在注册或登录时保存在本地存储中的与电子邮件相关的所有项目。我还保存了带有待办事项的电子邮件。要获取特定待办事项的redux操作是:
return dispatch => {
dispatch(itemsLoading())
localStorage.getItem('email')
const queryParams = '?search=' + createdBy + '&orderBy="register_date"&equalTo="' + register_date + '"';
axios.get('/api/todos')
.then(res => {
console.log(res.data)
})
.catch(err => {
console.log('error to search')
// dispatch(fetchOrderFail(err))
})
}
}```
在您的axios get请求中,您似乎没有在url中包括查询参数。您也不会以任何方式存储localStorage请求。
我也不确定您的查询参数的结构,但是作为一个入门者,我会像这样重组您的api请求:
import axios from 'axios'
export const getTodos = () => {
return dispatch => {
dispatch(itemsLoading())
const createdBy = localStorage.getItem('email')
axios.get(`/api/todos?search=${createdBy}`)
.then(res => console.log(res))
.catch(error => console.log(error))
}
}
您可能还希望在.then()
处理程序中调度成功操作,并在处理程序中调度失败操作.catch()
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句