Skip to content

Commit

Permalink
六: 1.完善类组件功能
Browse files Browse the repository at this point in the history
  • Loading branch information
zh-lx committed Nov 10, 2021
1 parent 5592e5f commit 6144a2d
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/index.js
Expand Up @@ -5,14 +5,22 @@ import './index.css';
class ClassComponent extends Component {
constructor(props) {
super(props);
this.state = {};
this.state = { count: 0 };
}

addCount = () => {
this.setState({
count: this.state.count + 1,
});
};

render() {
return (
<div className="class-component">
<div>this is a class Component</div>
<div>prop value is: {this.props.value}</div>
<div>count is: {this.state.count}</div>
<input type="button" value="add count" onClick={this.addCount} />
</div>
);
}
Expand Down

0 comments on commit 6144a2d

Please sign in to comment.