美文网首页
#11 获取文本的高度

#11 获取文本的高度

作者: 康乐芳华 | 来源:发表于2017-12-19 12:00 被阅读0次

完成 Post 组件,接受一个字符串的 content 作为 propsPost 会把它显示到自己的 <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>)
  }
}

相关文章

网友评论

      本文标题:#11 获取文本的高度

      本文链接:https://www.haomeiwen.com/subject/quybwxtx.html