tab.vue 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <template>
  2. <view :class="{ active, inactive: !active, tab: true }" :style="shouldShow ? '' : 'display: none;'">
  3. <slot v-if="shouldRender"></slot>
  4. </view>
  5. </template>
  6. <script>
  7. export default {
  8. props: {
  9. dot: {
  10. type: Boolean,
  11. },
  12. name: {
  13. type: [Number, String],
  14. value: ''
  15. }
  16. },
  17. inject: ['tabs'],
  18. data() {
  19. return {
  20. active: false,
  21. shouldShow: false,
  22. shouldRender: false
  23. }
  24. },
  25. created() {
  26. this.tabs.childrens.push(this)
  27. },
  28. mounted() {
  29. this.update()
  30. },
  31. methods: {
  32. getComputedName: function() {
  33. if (this.data.name !== '') {
  34. return this.data.name;
  35. }
  36. return this.index;
  37. },
  38. updateRender: function(active, parent) {
  39. let parentData = parent;
  40. this.inited = this.inited || active;
  41. this.active = active
  42. this.shouldRender = this.inited
  43. this.shouldShow = active
  44. },
  45. update: function() {
  46. if (this.tabs) {
  47. this.tabs.updateTabs();
  48. }
  49. }
  50. },
  51. computed: {
  52. changeData() {
  53. const {
  54. dot,
  55. info,
  56. } = this
  57. return {
  58. dot,
  59. info,
  60. }
  61. }
  62. },
  63. watch: {
  64. changeData(value) {
  65. this.update()
  66. },
  67. name(val) {
  68. this.update()
  69. }
  70. },
  71. }
  72. </script>
  73. <style>
  74. .tab.active {
  75. height: auto;
  76. }
  77. .tab.inactive {
  78. height: 0;
  79. overflow: visible;
  80. }
  81. </style>