Ref

  1. define('my-first-element', class extends WeElement {
  2. onClick = (evt) => {
  3. console.log(this.h1)
  4. }
  5. render(props) {
  6. return (
  7. <div>
  8. <h1 ref={e => { this.h1 = e }} onClick={this.onClick}>Hello, world!</h1>
  9. </div>
  10. )
  11. }
  12. })
  13. render(<my-first-element></my-first-element>, 'body')

在元素上添加 ref={e => { this.anyNameYouWant = e }} ,然后你就可以 JS 代码里使用 this.anyNameYouWant 访问该元素。