redux学习再总结

137 阅读1分钟

1.在项目中创建文件夹store

image.png 2.在store文件中,创建index.js文件去创建store

image.png 3.如果不引入reducer,创建的store将是空数据,必须让reducer给store传入数据

4.创建reducer.js文件创建reducer

image.png 5.拿到store初始化的数据(this.state = store.getState())

image.png 6.监听store数据的变化。在constructor函数中使用(store.subscribe(回调函数))实现回调函数更新state

image.png 7.改表store里的值

image.png

image.png