dva组件,connect链接 models,所有的 state,或方法都通过 this.props获取
function User(props) {}
function mapStateToProps({ user, loading }) {
return {
...user,
// loading: loading.global,
loading: loading.models.user
};
}
function mapDispatchToProps(dispatch) {
return {
_$fetchUser: payload => dispatch({ type: 'user/fetchUser', payload }),
};
}
export default connect(mapStateToProps, mapDispatchToProps)(User);
loading
- loading.global 全局 loading
- loading.models[namespace] 当前 models下的 loading
- loading.effects[namespace/func] 当前请求的 loading
connect
connect(TableList)()
@connect
装饰器语法
@connect(state, dispatch)
@connect(
state => state.home,
dispatch => {
_@saveAction: payload => dispatch({type: 'home/list', paylod}),
_@asyncTable: payload => dispatch({type: 'home/asyncTable', payload})
}
)