Component Splitting
The current App.vue has complete functionality, but all the code is crammed together.
Next we will do component splitting; you will learn:
- How to write highly reusable child components in a Tailwind v4 environment.
- How to use defineProps and defineEmits to pass data between JS components.
Now in src/components directory, create the following four files:
TaskHeader.vue(pure display)TaskInput.vue(input logic)TaskFilter.vue(state switching)TaskItem.vue(single task)

TaskHeader.vue — static display component
This component needs no JS logic; it only displays UI.
In Tailwind v4, we continue to use the new gradient syntax.
Example
TaskHub
Vue 3 + Tailwind v4 Hands-on
TaskInput.vue — using defineEmits to send data
This component is responsible for getting user input. When the user clicks add, it does not modify the data directly, but notifies the parent component via emit.
Example
v-model="title"
@keyup.enter="handleSubmit"
placeholder="What to accomplish today?"
class="flex-1 bg-slate-50 border-none rounded-2xl px-4 py-3 focus:ring-2 focus:ring-brand/50 outline-none transition-all"
/>
+
TaskFilter.vue — v-model communication between components
In Vue 3.4+, it is recommended to use defineModel() for two-way binding. This is very efficient in Tailwind v4 UI switching.
Example
TaskItem.vue — using defineProps to receive data
It is the most core child component, responsible for displaying a single task and reporting modify/delete operations.
Example
type="checkbox"
:checked="task.isCompleted"
@change="emit('toggle', task.id)"
class="w-5 h-5 accent-brand cursor-pointer"
/>
{{ task.title }}
✕
Refactored App.vue (logic hub)
The current App.vue has become a clean commander, only responsible for managing raw data and handling instructions from child components.
Example
v-for="task in filteredTasks" :key="task.id" :task="task" @toggle="handleToggleTask" @remove="handleRemoveTask" />
No related tasks yet...
Core Knowledge Points Summary
defineProps (parent to child):
TaskItemPasspropsreceives task data. In Vue, Props areread-only. Child components must never directly modifyprops's value; this is the "one-way data flow".
defineEmits (child to parent):
- When a child component needs to change data (such as delete or check), it uses
emitto emit a signal, and the parent component executes the actual modification logic. This ensures there is only one source of data modification, making debugging easier.
defineModel (two-way binding magic tool):
- in
TaskFilter, we used thedefineModelintroduced in Vue 3.4. It greatly simplifies the state-sync code between parent and child components, no longer needing to manually writepropsand listen to@update:modelValue.
Tailwind v4 Reusability:
- Even after splitting components, Tailwind's atomic class names still work. Because the Vite plugin automatically scans
src's all.vuefiles and generates the corresponding styles.