TechTabPane.vue 949 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <template>
  2. <div class="tech-tab-pane" v-show="active">
  3. <slot></slot>
  4. </div>
  5. </template>
  6. <script>
  7. export default {
  8. name: 'TechTabPane',
  9. props: {
  10. label: { type: String, required: true }, // 头部显示的文字
  11. name: { type: [String, Number], required: true } // 唯一标识符
  12. },
  13. computed: {
  14. // 核心:动态判断自己是否被选中
  15. active() {
  16. // 通过 this.$parent 拿到 TechTabs 组件绑定的 v-model (即 value 属性)
  17. return this.$parent.value === this.name;
  18. }
  19. },
  20. created() {
  21. // 组件创建时,把自己注册到父组件的 panes 数组中去,让父组件能渲染出头部
  22. if (this.$parent && this.$parent.addPane) {
  23. this.$parent.addPane(this);
  24. }
  25. },
  26. beforeDestroy() {
  27. if (this.$parent && this.$parent.removePane) {
  28. this.$parent.removePane(this);
  29. }
  30. }
  31. };
  32. </script>
  33. <style scoped>
  34. .tech-tab-pane {
  35. width: 100%;
  36. height: 100%;
  37. }
  38. </style>