tabs.vue 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <script>
  2. export default {
  3. name: "LemonTabs",
  4. props: {
  5. activeIndex: String
  6. },
  7. data() {
  8. return {
  9. active: this.activeIndex
  10. };
  11. },
  12. mounted() {
  13. if (!this.active) {
  14. this.active = this.$slots["tab-pane"][0].data.attrs.index;
  15. }
  16. },
  17. render() {
  18. const pane = [];
  19. const nav = [];
  20. this.$slots["tab-pane"].map(vnode => {
  21. const { tab, index } = vnode.data.attrs;
  22. pane.push(
  23. <div class="lemon-tabs-content__pane" v-show={this.active == index}>
  24. {vnode}
  25. </div>
  26. );
  27. nav.push(
  28. <div
  29. class={[
  30. "lemon-tabs-nav__item",
  31. this.active == index && "lemon-tabs-nav__item--active"
  32. ]}
  33. on-click={() => this._handleNavClick(index)}
  34. >
  35. {tab}
  36. </div>
  37. );
  38. });
  39. return (
  40. <div class="lemon-tabs">
  41. <div class="lemon-tabs-content">{pane}</div>
  42. <div class="lemon-tabs-nav">{nav}</div>
  43. </div>
  44. );
  45. },
  46. methods: {
  47. _handleNavClick(index) {
  48. this.active = index;
  49. }
  50. }
  51. };
  52. </script>
  53. <style lang="stylus">
  54. @import '~styles/utils/index'
  55. pane-color = #f6f6f6
  56. +b(lemon-tabs)
  57. background pane-color
  58. +b(lemon-tabs-content)
  59. width 100%
  60. height 100%
  61. padding 15px
  62. +e(pane)
  63. //scrollbar-light()
  64. //overflow-y auto
  65. height 100%
  66. width 100%
  67. +b(lemon-tabs-nav)
  68. display flex
  69. background #eee
  70. +e(item)
  71. line-height 38px
  72. padding 0 15px
  73. cursor pointer
  74. transition all .3s cubic-bezier(0.645, 0.045, 0.355, 1)
  75. +m(active)
  76. background pane-color
  77. </style>