Created
April 24, 2018 07:39
-
-
Save yyong37/f9394e51a758fd4efe9e0a2a0b0d73c4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Post extends Component { | |
constructor () { | |
super() | |
this.state = { content: '' } | |
} | |
componentWillMount () { | |
this._loadData() | |
} | |
async _loadData () { | |
this.setState({ content: '数据加载中...' }) | |
const content = await getPostData() | |
this.setState({ content }) | |
} | |
render () { | |
return ( | |
<div> | |
<div className='post-content'>{this.state.content}</div> | |
<button onClick={() => { | |
this._loadData() | |
}}>刷新</button> | |
</div> | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment