Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Component Splitting

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:

Now in src/components directory, create the following four files:

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

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

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

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

Core Knowledge Points Summary

defineProps (parent to child):

defineEmits (child to parent):

defineModel (two-way binding magic tool):

Tailwind v4 Reusability: