TechTabPane.vue 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <template>
  2. <div class="tech-tab-pane" v-show="active">
  3. <div v-if="loading" class="tab-pane-loading">加载中...</div>
  4. <slot v-else></slot>
  5. </div>
  6. </template>
  7. <script>
  8. export default {
  9. name: 'TechTabPane',
  10. props: {
  11. label: { type: String, required: true }, // 头部显示的文字
  12. name: { type: [String, Number], required: true }, // 唯一标识符
  13. loading: { type: Boolean, default: false }
  14. },
  15. computed: {
  16. // 核心:动态判断自己是否被选中
  17. active() {
  18. // 通过 this.$parent 拿到 TechTabs 组件绑定的 v-model (即 value 属性)
  19. return this.$parent.value === this.name;
  20. }
  21. },
  22. created() {
  23. // 组件创建时,把自己注册到父组件的 panes 数组中去,让父组件能渲染出头部
  24. if (this.$parent && this.$parent.addPane) {
  25. this.$parent.addPane(this);
  26. }
  27. },
  28. beforeDestroy() {
  29. if (this.$parent && this.$parent.removePane) {
  30. this.$parent.removePane(this);
  31. }
  32. }
  33. };
  34. </script>
  35. <style scoped>
  36. .tech-tab-pane {
  37. width: 100%;
  38. flex: 1;
  39. min-height: 0;
  40. display: flex;
  41. flex-direction: column;
  42. }
  43. .tab-pane-loading {
  44. display: flex;
  45. align-items: center;
  46. justify-content: center;
  47. height: 120px;
  48. color: #758599;
  49. font-size: 14px;
  50. }
  51. </style>