账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    mobx多个store问题
    56
    0

    我在react中使用mobx做状态管理实现了简单计数器demo,如果该页面今后需要添加新的功能,我希望不同功能存放在不同的store,请问这要如何实现

    countStore.js

    import { observable,action, computed } from 'mobx';
    class CountStore{
        @observable num = 0;
        @computed get displayResult(){
            return this.num;
        }
    }
    
    export default CountStore;

    app.js

    import React, { Component } from 'react';
    import { render } from 'react-dom';
    import Count from './count';
    import Display from './display';
    import CountStore from "../store/countStore";
    const CountStores = new CountStore();
    class Countapp extends Component{
        constructor(props){
            super(props)
        }
    
        render(){
            return <div>
                
                <Count store={CountStores}/>
                <Display store={CountStores}/>
                
            </div>
        }
    }
    
    export default Countapp;
    2
    打赏
    收藏
    点击回答
    您的回答被采纳后将获得:提问者悬赏的 11 元积分
        全部回答
    • 0
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部