V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
sivacohan
V2EX  ›  问与答

Antd Pro 里 dva 的 connect 是怎么用的

  •  
  •   sivacohan · 2020-03-17 20:27:41 +08:00 · 2030 次点击
    这是一个创建于 1517 天前的主题,其中的信息可能已经有所发展或是发生改变。
    export default connect(
      ({
        loading,
        accountAndcenter,
      }: {
        loading: { effects: { [key: string]: boolean } };
        accountAndcenter: ModalState;
      }) => ({
        currentUser: accountAndcenter.currentUser,
        currentUserLoading: loading.effects['accountAndcenter/fetchCurrent'],
      }),
    )(Center);
    

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

    3 条回复    2020-03-17 23:21:25 +08:00
    aaronlam
        1
    aaronlam  
       2020-03-17 21:32:59 +08:00   ❤️ 1
    dva 的 connect 函数会有一个形参,这个形参里包含所有的 model 的信息,你就是从这个形参里通过 JS 的解构,解构出来了 loading 和 accountAndcenter
    sivacohan
        2
    sivacohan  
    OP
       2020-03-17 22:06:18 +08:00 via iPhone
    @aaronlam 所有 model 是指把整个 model 的树给传进来吗?
    aaronlam
        3
    aaronlam  
       2020-03-17 23:21:25 +08:00
    @sivacohan 恩是的,纠正一下上面的说法,准确的说是 connect 函数的回调形参,你可以在你这个回调函数里 cansole.dir 一下这个形参,你就可以看到他的详细结构了。。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   945 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 21:55 · PVG 05:55 · LAX 14:55 · JFK 17:55
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.