react.js初学者 刚看文档


  • 0

    链接文本
    class LikeButton {
    constructor () {
    this.state = { isLiked: false }
    }

    changeLikeText () {
      const likeText = this.el.querySelector('.like-text')
      this.state.isLiked = !this.state.isLiked
      likeText.innerHTML = this.state.isLiked ? '取消' : '点赞'
    }
    
    render () {
      this.el = createDOMFromString(`
        <button class='like-button'>
          <span class='like-text'>点赞</span>
          <span>👍</span>
        </button>
      `)
      this.el.addEventListener('click', this.changeLikeText.bind(this), false)
      return this.el
    }
    

    }
    没看明白 changeLikeText()对DOM进行了什么操作了


  • 0

    0_1534848421469_upload-88ae2ca0-6b7f-48f0-821f-419566a59e99


登录后回复
 

与 ScriptOJ 的连接断开,我们正在尝试重连,请耐心等待