【发布时间】:2021-01-20 11:19:08
【问题描述】:
我正在使用 redux-thunk 在我的 react-native 应用程序中使用 redux 设置。这是简单的登录操作
export const doLogin=(request, onSuccess, onError)=>{
return dispatch=>{
console.log(request)
axios.post(`/AppUser/LoginValidation`, request).then(res=>{
console.log(res.data)
if(res.data.isSuccess=== true){
dispatch({
type:LOGIN,
payload:{
auth_token: res.data.authToken,
responseResult: res.data.responseResult,
loggedIn: true
}
})
onSuccess && onSuccess();
}else{
dispatch({
type: ERROR,
payload: res.data.message
})
onError && onError();
}
})
.catch(err=>{
console.log('err',err )
})
}
}
这样我就在前端使用了上面的代码:
props.doLogin(data,()=>{
action.setErrors({password: props.errorMsg})
// action.resetForm();
// setMobileno(null)
props.navigation.navigate('FLayout', { screen:'Home' })
})
如果登录 ID 和密码正确,它会重定向我。如果我输入了无效的 ID 和密码,它仍然会将我重定向到主页,而不是向我显示消息。
【问题讨论】:
标签: reactjs react-native redux react-redux redux-thunk