gpt4 book ai didi

javascript - 搜索与本地存储项相关的数据

转载 作者:行者123 更新时间:2023-11-28 03:03:18 25 4
gpt4 key购买 nike

我正在使用简单的 React todo 应用程序。我想搜索与注册或登录时保存在本地存储中的电子邮件相关的所有项目。我还保存了包含待办事项的电子邮件。用于获取特定待办事项的 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() 处理程序中分派(dispatch)成功操作,并在 .catch() 处理程序中分派(dispatch)失败操作。

关于javascript - 搜索与本地存储项相关的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60804052/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com