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

dva学习笔记 #13

Open
wanCheng7 opened this issue Mar 24, 2020 · 0 comments
Open

dva学习笔记 #13

wanCheng7 opened this issue Mar 24, 2020 · 0 comments

Comments

@wanCheng7
Copy link
Owner

关于model

相对于react-redux,最大的变化就是引入了model,相当于对之前的action和reducer做了一个封装,并且将一部操作和一些副作用的操作抽离到了effects中。然后要注意,effects中的函数是generater函数。

然后注意一下namespace命名空间问题,每一个model都有一个单独的命名空间,在本model调用reducer或者effects时,不需要写命名空间,但是调用其他model时一定记得要加上,格式是命名空间/方法名

关于按需加载组件和model

对于可以按需加载的组件,可以使用dva内置的dynamic按需加载

import dynamic from 'dva/dynamic';

model中的方法要加载成功之后才能被别的地方调用。

call和put

dva 提供多个 effect 函数内部的处理函数,比较常用的是 callput

  • call:执行异步函数
  • put: 发出一个 Action,类似于 dispatch

参考

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant