蠱毒傳說
2022-05-26 11:19:25
我在簡單的反應待辦事項應用程序中工作。我想搜索與注冊或登錄時保存在本地存儲中的電子郵件相關的所有項目。我還保存了帶有待辦事項的電子郵件.. 用于獲取特定待辦事項的 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)) }) } }```
2 回答

慕雪6442864
TA貢獻1812條經驗 獲得超5個贊
在您的 axios 獲取請求中,您似乎沒有在 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()。
添加回答
舉報
0/150
提交
取消