mirror of
https://github.com/YMFE/yapi.git
synced 2024-12-27 05:30:14 +08:00
添加react-redux、redux
This commit is contained in:
parent
7dfb9489cb
commit
68dd0b4c96
@ -1,4 +1,5 @@
|
||||
import React, { Component } from 'react'
|
||||
import './store.js'
|
||||
import Routes from './routes'
|
||||
|
||||
class App extends Component {
|
||||
|
5
client/ReduxContainer.js
Normal file
5
client/ReduxContainer.js
Normal file
@ -0,0 +1,5 @@
|
||||
import LoginRedux from './containers/Login/Login_redux.js'
|
||||
|
||||
export default {
|
||||
LoginRedux
|
||||
}
|
@ -10,8 +10,10 @@ class Login extends Component {
|
||||
}
|
||||
|
||||
render () {
|
||||
console.log(this.props)
|
||||
return (
|
||||
<acticle className="login-main">
|
||||
<span>{this.props.value}{this.props.per}</span>
|
||||
<section className="login-box">
|
||||
<div className="content">
|
||||
<Input
|
||||
|
27
client/containers/Login/Login_container.js
Normal file
27
client/containers/Login/Login_container.js
Normal file
@ -0,0 +1,27 @@
|
||||
import React, { Component } from 'react'
|
||||
import { createStore, combineReducers } from 'redux'
|
||||
import { connect } from 'react-redux'
|
||||
import Login from './Login.js'
|
||||
|
||||
// Action
|
||||
const increaseAction = { type: 'increase' }
|
||||
|
||||
function mapStateToProps(state) {
|
||||
return {
|
||||
per: '测试数据',
|
||||
}
|
||||
}
|
||||
|
||||
function mapDispatchToProps(dispatch) {
|
||||
return {
|
||||
onIncreaseClick: () => dispatch(increaseAction)
|
||||
}
|
||||
}
|
||||
|
||||
const App = connect(
|
||||
mapStateToProps,
|
||||
mapDispatchToProps
|
||||
)(Login)
|
||||
|
||||
export default App
|
||||
|
11
client/containers/Login/Login_redux.js
Normal file
11
client/containers/Login/Login_redux.js
Normal file
@ -0,0 +1,11 @@
|
||||
import React, { Component } from 'react'
|
||||
|
||||
export default function (state = 3, action) {
|
||||
const count = state
|
||||
switch (action.type) {
|
||||
case 'increasec':
|
||||
return count + 1
|
||||
default:
|
||||
return state
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
import Home from './Home/Home.js'
|
||||
import Login from './Login/Login.js'
|
||||
import Login from './Login/Login_container.js'
|
||||
import ProjectGroups from './ProjectGroups/ProjectGroups.js'
|
||||
|
||||
export {
|
||||
|
@ -1,8 +1,16 @@
|
||||
import React from 'react'
|
||||
import ReactDOM from 'react-dom'
|
||||
import App from './App'
|
||||
import { createStore, combineReducers } from 'redux'
|
||||
import { Provider, connect } from 'react-redux'
|
||||
import ReduxContainer from './redux.js'
|
||||
|
||||
// 合并 redux 创建stroe
|
||||
const store = createStore(combineReducers( ReduxContainer ))
|
||||
|
||||
ReactDOM.render(
|
||||
<App />,
|
||||
<Provider store={store}>
|
||||
<App />
|
||||
</Provider>,
|
||||
document.getElementById('yapi')
|
||||
)
|
||||
)
|
||||
|
28
client/store.js
Normal file
28
client/store.js
Normal file
@ -0,0 +1,28 @@
|
||||
import React, { Component } from 'react'
|
||||
import { createStore, combineReducers } from 'redux'
|
||||
import Login from './containers/Login/Login_redux.js'
|
||||
import { Provider, connect } from 'react-redux'
|
||||
|
||||
// const store = createStore(combineReducers({Login}))
|
||||
|
||||
// const increaseAction = { type: 'increase' }
|
||||
|
||||
// function mapStateToProps(state) {
|
||||
// return {
|
||||
// value: 4444,
|
||||
// per: 4444444,
|
||||
// }
|
||||
// }
|
||||
|
||||
// function mapDispatchToProps(dispatch) {
|
||||
// return {
|
||||
// onIncreaseClick: () => dispatch()
|
||||
// }
|
||||
// }
|
||||
|
||||
// const App = connect(
|
||||
// mapStateToProps,
|
||||
// mapDispatchToProps
|
||||
// )(Login)
|
||||
|
||||
// export { store }
|
@ -27,6 +27,7 @@
|
||||
"mongoose": "4.10.8",
|
||||
"mongoose-auto-increment": "^5.0.1",
|
||||
"node-sass-china": "^4.5.0",
|
||||
"redux": "^3.7.1",
|
||||
"ykit-config-antd": "^0.1.3",
|
||||
"ykit-config-react": "^0.4.4"
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user