Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请教effect中读取state的值的问题 #1103

Closed
jackyren0 opened this issue Jul 31, 2017 · 4 comments
Closed

请教effect中读取state的值的问题 #1103

jackyren0 opened this issue Jul 31, 2017 · 4 comments
Labels

Comments

@jackyren0
Copy link

jackyren0 commented Jul 31, 2017

state:{
  user: {username: '1'}
},
subscriptions: {
  setup({dispatch}) {
    dispatch({type: 'getState'});
  },
},
effects: {
  *getState({}, {call, put, select}) {
    const user = yield select(state=>state.user);
    ...
  },
},

取得的user值是undefined。
不知道哪里出了问题,请大神指点,谢谢!
dva版本:1.2.1

@sorrycc
Copy link
Member

sorrycc commented Jul 31, 2017

namespace 配了吗?

@jackyren0
Copy link
Author

namespace: 'main',

@sorrycc
Copy link
Member

sorrycc commented Jul 31, 2017

yield select(state => state.main.user); 那得这样取,试着理解下 namespace 的含义。

@jackyren0
Copy link
Author

明白了,可以取到了,谢谢!

@sorrycc sorrycc closed this as completed Aug 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants