noSlot

对于写一些 omi 插件,noSlot 非常有用,它不会把 children 插入到 DOM 中,并且你可以在插件中通过 props.children 拿到虚拟 DOM。

  1. import { define, render, WeElement } from 'omi'
  2. define('fancy-tabs', class extends WeElement {
  3. static noSlot = true
  4. render() {
  5. return [
  6. <div id="tabs">
  7. <slot id="tabsSlot" name="title" />
  8. </div>,
  9. <div id="panels">
  10. <slot id="panelsSlot" />
  11. </div>,
  12. <div>Show me only when noSlot is true!</div>
  13. ]
  14. }
  15. })
  16. define('my-app', class extends WeElement {
  17. render() {
  18. return (
  19. <div>
  20. <fancy-tabs>
  21. <button slot="title">Title</button>
  22. <button slot="title" selected>
  23. Title 2
  24. </button>
  25. <button slot="title">Title 3</button>
  26. <section>content panel 1</section>
  27. <section>content panel 2</section>
  28. <section>content panel 3</section>
  29. </fancy-tabs>
  30. </div>
  31. )
  32. }
  33. })
  34. render(<my-app />, 'body')