Skip to content

Instantly share code, notes, and snippets.

@yyong37
Created April 24, 2018 07:39
Show Gist options
  • Save yyong37/f9394e51a758fd4efe9e0a2a0b0d73c4 to your computer and use it in GitHub Desktop.
Save yyong37/f9394e51a758fd4efe9e0a2a0b0d73c4 to your computer and use it in GitHub Desktop.
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