import React from 'react';
class Basic extends React.Component {
constructor() {
super();
this.state = {
changeValue: '', // 任务栏改变值
isLocked: true,
value: 2
}
this.changeHandle = this.changeHandle.bind(this);
this.setValue = this.setValue.bind(this);
}
setValue() {
this.setState({
value: this.state.value + 1
})
}
changeHandle(content, event){
console.log('传递的内容 = ' + content)
this.setState({
isLocked: !this.state.isLocked
})
}
componentWillMount() {
console.log('组件将要渲染')
this.setState({
value: this.state.value + 1
})
}
componentDidMount(){
console.log('组件正式渲染')
}
render() {
console.log('渲染render()')
var divStyle = {
}
var valueStyle = {
fontSize: 50,
color: '#FF0004'
}
return (
<div id style={divStyle} className='data-line'>
<div>
<div style={valueStyle} onClick={this.setValue}>{this.state.value}</div>
</div>
<div>
{this.state.isLocked ?
<button onClick={this.changeHandle.bind(this, '人生不如意')}>改变</button> :
<button>无法点击按钮</button>
}
</div>
</div>
)
}
}
export default Basic;
开心每一天1111
茅侃侃
相关分类