文章参考
使用react-mixin插件引入
import reactMixin from 'react-mixin'
let myObj = {
username:"huangbioa",
speak: function(){
alert(this.state.type);
}
};
class MyIndex extends BaseComponent {
state = {
type: 'money',
};
constructor(props){
super(props);
this.handleChange = this.handleChange.bind(this);
}
handleChange(e){
this.setState({
type: e.target.value
})
this.speak();
this.testAction();
}
render () {
return (
<div>
<input type="text" onChange={this.handleChange.bind(this)} value={this.state.type} />
</div>
);
}
}
reactMixin.onClass(MyIndex,myObj);
使用extends继承基类
import React from 'react';
class BaseComponent extends React.Component {
constructor(props){
super(props);
}
testAction(){
console.log("testAction");
alert(this.state.type);
}
}
export default BaseComponent;