Counter.actions.jsCounter.js Counter.actions.jsexport const increment = () => ({ type:‘increment’ }) export const decrement = () => ({ type:‘decrement’ }) export const increment_n = (payload) => ({ type:‘increment_n’, payload }) Counter.jsimportReactfrom‘react’ import { connect } from‘react-redux’ import { bindActionCreators } from‘redux’ import * as counterActions from‘../Store/Actions/Counter.actions’ //* 是导入所有对象在counterActions中 functionCounter(props) { console.log(props) return ( <div> <buttononClick={props.increment}>+1</button> <buttononClick={() => { props.increment_n(5) }}>+5</button> <span>{props.count}</span> <buttononClick={props.decrement}>-1</button> </div> ) } const mapStateToProps = state=> ({ count:state.count }) //bindActionCreators传入一个对象和dispatch,自动为每个函数dispatch const mapDispatchToProps = dispatch => ({ …bindActionCreators(counterActions, dispatch) }) export default connect(mapStateToProps, mapDispatchToProps)(Counter)