redux

redux简单分为3步 放值 赋值 取值

       放值:(1. 先将放数据的方法(domeFun)放到props中,通过 connect 的 mapDispatchToProps参数来放。

                (2. 将数据放到方法 (domeFun) 中, 通过dispatch发送一个action给reducer(action里带类型和数据如:{type:"AAA",data:"数据"})

       赋值:(1.  在reducer中声明一个state如:(let stated={name:''}),通过方法(domeFun)派发过来的action.type的不同,

                       将action.data赋值给state中的变量如(newDate.name = action.data,其中newData是新声明的变量通过stated深拷贝过来的对象,并return newData)

                (2.  在connect 的 mapStateToprops 中的state参数(state就等于所有的reducer也就是stor的内容)中拿到reducer中赋值后的变量如 :(state.name),

                       赋值给props中一个变量并输出如:(return {cuName:state.name})

       取值:(1.  在页面中使用时用this.props.cuName

原文地址:https://www.cnblogs.com/cnlg123/p/9970918.html