美文网首页
React常用api

React常用api

作者: sweetBoy_9126 | 来源:发表于2019-10-16 10:41 被阅读0次
    1. 获取dom
    class Button extends React.Component {
      constructor() {
        this.myRef = React.createRef()
      }
      render() {
        return (
          <div>
          <button ref={this.myRef} onClick={this.x.bind(this)}>dom</button>
          </div>
        )
      }
      x() {
        console.log(this.myRef.current)
      }
    }
    
    1. 渲染html
      使用dangerouslySetInnerHTML={{__html: list}}
      后面的list是你要渲染的数据,前面必须写__html,并且必须是双花括号

    相关文章

      网友评论

          本文标题:React常用api

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