https://github.com/pmg1989/dva-admin/blob/master/src/index.js
import dva from 'dva';
import { browserHistory } from 'dva/router';
import createLoading from 'dva-loading';
import { message } from 'antd';
import './index.html';
import './index.css';
// 3 秒
const ERROR_MSG_DURATION = 3;
// 1. Initialize
const app = dva({
history: browserHistory,
onError(e) {
message.error(e.message, ERROR_MSG_DURATION);
console.error("app onError -- ", error);
}
});
// 2. Plugins
app.use(createLoading());
// 3. Model
// Moved to router.js
// app.model(require('./models/users'))
// 4. Router for browserHistory
app.router(require('./router'));
// 5. Start
app.start('#root');
在父组件上直接调用父组件自身的方法来修改 state,调用的方式不对!
demo 1
props.onClickFunction
&this.props.onClickFunction
https://facebook.github.io/react/warnings/unknown-prop.html
https://facebook.github.io/react/docs/components-and-props.html#functional-and-class-components
stateless components
&function components
https://facebook.github.io/react/docs/context.html#referencing-context-in-stateless-functional-components
https://facebook.github.io/react/docs/react-without-jsx.html
The component can either be provided as a
string
, or as asubclass
of React.Component, or aplain function
for stateless components.组件可以作为字符串提供,也可以作为React.Component的子类提供,也可以作为无状态组件的普通函数提供。
elements
&components
https://facebook.github.io/react/docs/rendering-elements.html
controlled Components
&Uncontrolled Components
https://facebook.github.io/react/docs/forms.html#controlled-components
https://facebook.github.io/react/docs/uncontrolled-components.html
https://facebook.github.io/react/docs/lifting-state-up.html