随笔分类 - Redux
摘要:TodoList.js componentDidMount(){ store.subscribe(this.storeChange) //订阅 axios.get('https://........').then((res)=>{ const data=res.data const action=g
阅读全文
摘要:删除this,用props作为参数代替this.props 性能比类组件性能优秀 JSX语法必须引入React TodoListUI.js import React from 'react' import {Input,Button,List} from 'antd' const TodoListU
阅读全文
摘要:将组件中所用数据和方法通过props传给子UI组件,子UI组件调用这些数据和方法完成页面渲染(业务逻辑层的构造函数不变) TodtListUI.js import React, { Component } from 'react' import {Input,Button,List} from 'a
阅读全文
摘要:export const getListAction=(data)=>({ type:GET_LIST, data }) const action=getListAction(data) 调用该方法,取到的是括号内部的值 所以该写法可看作()=>{return{}} 首先这里用的时ES6的箭头函数
阅读全文
摘要:报错的意思应该是因为必须在组件挂载后订阅 componentDidMount(){ // store.subscribe(this.storeChange) //订阅 }
阅读全文
摘要:1.store必须是唯一的,多个store是坚决不允许的,只能有一个store空间 现在看 TodoList.js 的代码,就可以看到,这里有一个 /store/index.js 文件,只在这个文件中用 createStore() 方法,声明了一个 store,之后整个应用都在使用这个 store。
阅读全文
摘要:1.使用actionTypes.js文件定义Type减少代码冗余,代码复用 export const CHANGE_INPUT='changeInput' export const ADD_ITEM='addItem' export const DELETE_ITEM='deleteItem' im
阅读全文
摘要:TodoList.js import React, { Component } from 'react' import {Input,Button,List} from 'antd' import store from './store'; class TodoList extends Compon
阅读全文
摘要:TodoList.js import React, { Component } from 'react' import {Input,Button,List} from 'antd' import store from './store'; class TodoList extends Compon
阅读全文
摘要:扩展商店 1.浏览器里安装redux-devtools 谷歌: edge: 2.在项目的入口文件里 找到 createStore函数调用的地方,给它加第二个参数 window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENS
阅读全文
摘要:npm install --save redux react-redux //安装react-redux和redux "^4.2.0", 只装 redux也可 TodoList.js import React, { Component } from 'react' import {Input,But
阅读全文
摘要:npm install --save redux react-redux //安装react-redux和redux一般情况下安装redux即可,react-redux用法暂不明确
阅读全文