import {connect,Provider} from 'react-redux'
import {store} from '../store/index'

<Provider store={store}>
<HashRouter>
<Row>
<Col span={6}><Link to="/">首页</Link></Col>
<Col span={6}><Link to="/login">登录</Link></Col>
<Col span={6}><Link to="/">注册</Link></Col>
<Col span={6}><Link to="/">管理中心</Link></Col>
</Row>
<Switch>
<Route exact path="/" component={App}></Route>
<Route path="/login" component={login}></Route>
</Switch>
</HashRouter>
</Provider>


const method=(dispatch,state)=>{
return {
onTodoClick: () => {
console.log(123)
console.log(state)
dispatch({type:'ADD_TO_CART',payload:'123'})
dispatch({type:'ok',payload:'123'})
}
}
}
const ste=(state)=>{
return {
sta:state.product.cart
}
}
export default connect(ste,method)(Login);

redux 仓库

import {createStore} from 'redux'//用于创建仓库
import {combineReducers} from 'redux'//
const initialState = {//state数据
cart: [
{
product: 'bread 700g',
quantity: 2,
unitCost: 90
},
{
product: 'milk 500ml',
quantity: 1,
unitCost: 47
}
],
count:1
}
const cartReducer = function(state=initialState, action) {//数据与action提交类型
switch(action.type){
case 'ADD_TO_CART':
state.cart.push(action.payload)
console.log(123)
break;
}
return state;
}
let admin = {
form: {
user: 'user',
pass: 'pass'
}
}
const adminReducer = function (state=admin,action){
switch(action.type){
case 'ok':
console.log(12312);
break;
}
return state
}
const allReducers = {//多个state数据集合
product: cartReducer,
admin: adminReducer
}
let a=combineReducers(allReducers)//通过com管理
export const store=createStore(a)//仓库