使用redux时 当监听state改变时作出操做react
import {connect} from 'react-redux' import store from "../../rudux/store" class LayoutMain extends React.Component { constructor(props){ super(props) store.subscribe(() => { console.log('state状态改变了,新状态以下') console.log(store.getState()) this.getMenu() }) } } const mapStateToProps = state =>{ if(state){ return{ menuLength:state } } } export default connect(mapStateToProps)(LayoutMain);