TabView.vue 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <template>
  2. <div class='tab_view'>
  3. <div class='tab_view__tabs'>
  4. <div class='tab_view__tab' :class='{"tab_view__tab--selected": tabIndex === 0}' @click='changeTab(0)'>{{tabs[0]}}</div>
  5. <div class='tab_view__tab' :class='{"tab_view__tab--selected": tabIndex === 1}' @click='changeTab(1)'>{{tabs[1]}}</div>
  6. </div>
  7. <div class='tab_view__content'>
  8. <slot name='first' v-if='tabIndex === 0'></slot>
  9. <slot name='second' v-if='tabIndex === 1'></slot>
  10. </div>
  11. </div>
  12. </template>
  13. <script>
  14. import mapGetters from 'vuex';
  15. export default {
  16. name: 'TabView',
  17. props: ['tabs', 'name'],
  18. methods: {
  19. changeTab (index) {
  20. this.$store.commit({
  21. type: 'setTab',
  22. tab: 'account',
  23. index: index
  24. });
  25. }
  26. },
  27. computed: {
  28. tabIndex () {
  29. return this.$store.state.tabs[this.name];
  30. }
  31. }
  32. }
  33. </script>
  34. <style lang='scss' scoped>
  35. @import '../assets/scss/variables.scss';
  36. .tab_view {
  37. @at-root #{&}__tabs {
  38. display: flex;
  39. }
  40. @at-root #{&}__tab {
  41. flex-grow: 1;
  42. text-align: center;
  43. cursor: pointer;
  44. font-weight: 400;
  45. padding: 0.5rem 0;
  46. background-color: $color__gray--primary;
  47. transition: background-color 0.2s;
  48. &:hover {
  49. background-color: $color__gray--darker;
  50. }
  51. &:active {
  52. background-color: rgba(210, 210, 210, 1);
  53. }
  54. @at-root #{&}--selected {
  55. background-color: #fff;
  56. &:hover {
  57. background-color: #fff;
  58. }
  59. &:active {
  60. background-color: #fff;
  61. }
  62. }
  63. }
  64. @at-root #{&}__content {
  65. background-color: #fff;
  66. padding: 1rem;
  67. }
  68. }
  69. </style>