ui-group-option.vue 888 B

12345678910111213141516171819202122232425262728293031323334
  1. <template>
  2. <div class="group-option">
  3. <span v-if="props.label" class="group-option-label">
  4. {{ props.label }}
  5. </span>
  6. <slot />
  7. </div>
  8. </template>
  9. <script setup>
  10. import { getCurrentInstance, inject, onBeforeMount, onUnmounted } from 'vue'
  11. import { Relation } from './constant'
  12. const props = defineProps({
  13. label: String,
  14. })
  15. const brotherInstances = inject(Relation)
  16. const instance = getCurrentInstance()
  17. if (brotherInstances.value) {
  18. onBeforeMount(() => (brotherInstances.value = [...brotherInstances.value, instance]))
  19. onUnmounted(() => {
  20. const index = brotherInstances.value.indexOf(instance)
  21. if (~index) {
  22. brotherInstances.value.splice(index, 1)
  23. brotherInstances.value = [...brotherInstances.value]
  24. }
  25. })
  26. }
  27. </script>
  28. <script>
  29. export default { name: 'UiGroupOption' }
  30. </script>