Antd Pro 里 dva 的 connect 是怎么用的

2020-03-17 20:27:41 +08:00
 sivacohan
export default connect(
  ({
    loading,
    accountAndcenter,
  }: {
    loading: { effects: { [key: string]: boolean } };
    accountAndcenter: ModalState;
  }) => ({
    currentUser: accountAndcenter.currentUser,
    currentUserLoading: loading.effects['accountAndcenter/fetchCurrent'],
  }),
)(Center);

这里的 loading accountAndCenter 是怎么传进去的?

2032 次点击
所在节点    问与答
3 条回复
aaronlam
2020-03-17 21:32:59 +08:00
dva 的 connect 函数会有一个形参,这个形参里包含所有的 model 的信息,你就是从这个形参里通过 JS 的解构,解构出来了 loading 和 accountAndcenter
sivacohan
2020-03-17 22:06:18 +08:00
@aaronlam 所有 model 是指把整个 model 的树给传进来吗?
aaronlam
2020-03-17 23:21:25 +08:00
@sivacohan 恩是的,纠正一下上面的说法,准确的说是 connect 函数的回调形参,你可以在你这个回调函数里 cansole.dir 一下这个形参,你就可以看到他的详细结构了。。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/653670

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX