【发布时间】:2021-08-30 16:40:01
【问题描述】:
我的应用程序在端口 3000 上运行。我想从运行在端口 5000 上的后端获取 redux 操作中的数据。
没有从 bakcend 获取数据。我没有拒绝错误。
前端/redux/categoryAction.js:
export const listCategories = () => async (dispatch) => {
try {
dispatch({ type: 'CATEGORY_LIST_REQUEST' })
const { data } = await fetch('http://localhost:5000/api/categories')
dispatch({
type: 'CATEGORY_LIST_SUCCESS',
payload: data
})
} catch (error) {
dispatch({
type: 'CATEGORY_LIST_FAIL',
payload: error.response && error.response.data.message
? error.response.data.message : error.message
})
}
}
【问题讨论】:
-
这能回答你的问题吗? How to overcome the CORS issue in ReactJS following answer 可能就是你要找的。span>
标签: node.js api redux fetch localhost