首页 > TAG信息列表 > storeChange
组件UI和业务逻辑的拆分
将组件中所用数据和方法通过props传给子UI组件,子UI组件调用这些数据和方法完成页面渲染(业务逻辑层的构造函数不变) TodtListUI.js import React, { Component } from 'react' import {Input,Button,List} from 'antd' class TodoListUI extends Component { render() {bind绑定(改变this指向)
constructor(props){ super(props) this.state=store.getState() this.changeInputValue=this.changeInputValue.bind(this) this.storeChange=this.storeChange.bind(this) this.clickBtn=this.clickBtn.bind(this) store.subscribe(this.storeInput体验redux流程
TodoList.js import React, { Component } from 'react' import {Input,Button,List} from 'antd' import store from './store'; class TodoList extends Component { constructor(props){ super(props) this.state=store.gCannot read properties of undefined (reading 'setState')
this的指向不对,需要用bind绑定this 例如 constructor(props){ super(props) this.state=store.getState() this.changeInputValue=this.changeInputValue.bind(this)//绑定 store.subscribe(this.storeChange)//订阅 }