ui-group-option.vue 832 B

1234567891011121314151617181920212223242526272829303132
  1. <template>
  2. <div class="group-option">
  3. <span class="group-option-label" v-if="props.label">
  4. {{ props.label }}
  5. </span>
  6. <slot />
  7. </div>
  8. </template>
  9. <script setup>
  10. import { Relation } from './constant'
  11. import { inject, onBeforeMount, onUnmounted, getCurrentInstance } from 'vue'
  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> export default { name: 'ui-group-option' } </script>