Welcome to VueAirport, a powerful composable for managing parent-child component relationships in Vue 3.
VueAirport is a generic check-in system designed for parent-child component registration patterns. Think of it like an airport check-in desk: parent components provide a check-in counter where child components register themselves with their data.
This pattern is particularly useful when building:
VueAirport implements a local Inversion of Control container.
In a traditional parent-child relationship, the parent component directly manages its children:
<!-- ❌ Traditional: Parent controls children -->
<script setup>
const tabs = ref([]);
const registerTab = (tab) => tabs.value.push(tab);
// Parent must expose registration method
// Children must know how to find and call it
</script>
With IoC, children control their own registration. The parent simply provides a "desk" (container) where children can check in:
<!-- ✅ IoC: Children register themselves -->
<script setup>
// Parent just creates a desk and provides it
const { createDesk } = useCheckIn();
const { desk } = createDesk('tabs');
// Children will register themselves automatically
// Parent receives updates via the reactive registry
</script>
Decoupling
Flexibility
Testability
Reusability
VueAirport uses Vue's provide/inject mechanism as its dependency injection system:
provide()inject()This approach follows the Dependency Inversion Principle: both parent and child depend on an abstraction (the desk interface), not on each other.
Imagine an airport check-in desk:
VueAirport provides a comprehensive set of features for component communication:
VueAirport excels in scenarios such as:
Tab Systems
Form Management
Shopping Carts
Navigation Menus
Here's a simple example to get you started:
<!-- Parent Component -->
<script setup lang="ts">
import { useCheckIn } from 'vue-airport';
interface TabItem {
label: string;
content: string;
}
const { createDesk } = useCheckIn<TabItem>();
const { desk } = createDesk('tabs');
const activeTab = ref('tab1');
</script>
<template>
<div>
<div v-for="item in desk.getAll()" :key="item.id">
<button @click="activeTab = item.id">{{ item.data.label }}</button>
</div>
</div>
</template>
<!-- Child Component -->
<script setup lang="ts">
import { useCheckIn } from 'vue-airport';
const props = defineProps<{
id: string;
label: string;
}>();
const { checkIn } = useCheckIn<TabItem>();
checkIn('tabs', {
autoCheckIn: true,
id: props.id,
data: () => ({ label: props.label, content: 'Tab content' })
});
</script>