effects loading细节
- loading 初始化,effecs可能为空,导致 effects里面的 keys为 undefined,需要设置个默认值
- loading.effects[‘user/getUserById’]
- effects里面的异步函数,如果直接 return,不会有 loading效果

import {connect} from 'dva';function App() {}function mapStateToProps({user, loading}) {return {defaultState: user,loading: loading.effects['user/getUserById'] || false,}}function mapDispatchToProps(dispatch) {return {_$getUser: payload => dispatch({type: 'user/getUserById', payload})}}export default connect(mapStateToProps, mapDispatchToProps)(App)
state使用规范
- 不推荐在 mapStateToProps里面,使用展开运算符,展开 state数据
- 使用defaultState来获取 state的数据
action
type,动作
payload,参数
{ type: '命名空间/方法名', payload: {} }
