我正在构建一个应用程序,后端工作正常(邮差已确认),但出现了下一个问题。
dbactions.js Redux操作文件
// LOAD USER
export const loadUser = () => async dispatch => {
try {
const res = await axios.get('http://localhost:5000/api/auth');
dispatch({
type: USER_LOADED,payload: res.data
});
} catch (error) {
dispatch({ type: AUTH_ERROR })
}
}
export const register = ( formData ) => async dispatch => {
try {
const config = {
headers: {
'Content-Type': 'application/json'
}
}
const res = await axios.post( 'http://localhost:5000/api/users',formData,config )
dispatch({
type: REGISTER_SUCCESS,payload: res.data,})
loadUser();
} catch (error) {
dispatch({
type: REGISTER_FAIL,payload: error.response.data.msg
})
}
}
当我在注册操作中致电LOADUSER()时,它报错,尝试了调度(LOADUSER())但没用。