#11 获取文本的高度
2017-12-19 本文已影响0人
康乐芳华
完成 Post
组件,接受一个字符串的 content
作为 props
,Post
会把它显示到自己的 <p>
元素内。
并且,点击 <p>
元素的时候,会使用 console.log
把元素的高度打印出来。
class Post extends Component {
constructor(props){
super(props)
this.handleClick = this.handleClick.bind(this)
}
handleClick(e){
console.log(e.target.clientHeight)
}
render () {
return (<p onClick={this.handleClick}>{this.props.content}</p>)
}
}