Core Business Development
Next we will build the core task management logic in App.vue.
The whole logic is as follows:
- Data flow: type content in the input box ->
v-modelupdatenewTaskTitle. - action triggered: press Enter -> execute
addTask->tasksto add an item to the array. - View update:
taskschanges -> triggersfilteredTasksto auto-recompute -> Vue re-renderslithe list. - State transition: click the filter button -> modify
currentFiltervalue -> triggers againfilteredTasksto compute -> the page displays different categories of tasks.
Basic Layout and Reactive Data
Write in src/App.vue:
Example
TaskHub
Vue 3 + Tailwind v4 Hands-on
v-model="newTaskTitle"
@keyup.enter="addTask"
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"
/>
+
- v-for="task in filteredTasks"
:key="task.id"
class="group flex items-center justify-between p-4 bg-slate-50 rounded-2xl border border-transparent hover:border-slate-200 hover:bg-white transition-all"
>
type="checkbox"
:checked="task.isCompleted"
@change="toggleTask(task.id)"
class="w-5 h-5 accent-brand cursor-pointer"
/>
{{ task.title }}
✕
No related tasks yet...
The interface after running is shown below:

Core Knowledge Points
1. Composition API
The above code demonstrates Vue 3's most core logic organization approach:
ref(reactivity foundation):tasks,newTaskTitleetc. are reactive references. In, modifying them must use.value(such astasks.value = ...), but in, write the variable name directly. Vue will automatically track changes to these values and update the UI.computed(computed property):filteredTasksis a very classic application. It is derived fromtasksandcurrentFilter.- Advantage: It is reactive and hascaching. If
tasksunchanged, it will not re-execute the filtering logic on multiple page renders.
2. List Rendering and Key Value
:keyThe importance: In Vue, list loops must providekey. Here we usecrypto.randomUUID()'s generated unique ID. This ensures that when the list order changes or an item is deleted, Vue can accurately identify the specific DOM node, avoiding rendering chaos (especially for lists with animations or input states).
3. Event Handling and Modifiers
@keyup.enter: This is aKey Modifiers. It makesaddTaskfunction only trigger when the user presses Enter, greatly improving the input experience.- Event Argument Passing:
removeTask(task.id)Demonstrates how to pass the current loop item's data to a function in the template.
4. Two-way Binding (v-model)
v-model="newTaskTitle"implements the synchronization between the input box and the variable.- Principle: It is actually
:valueand@input's syntax sugar.
5. Animation System (TransitionGroup)
- This is a built-in Vue component, specifically for handling lists (
v-for) adding and removing. - It automatically toggles CSS classes when elements enter or leave (such as
.list-enter-from). Combined with thestyleat the bottom of the code, it achieves the smooth slide-in and slide-out effect for list items.
Tailwind v4 Style Feature Explanation
Tailwind v4 emphasizes more than v3 native CSS capabilities and simplicity.
1. Brand-new gradient syntax
bg-linear-to-br: In v4, gradients no longer needbg-gradient-to-brthis verbose syntax; directly uselinear-to-方位, which is closer to native CSSlinear-gradient.
2. Opacity handling
text-blue-100/80:/80represents 80% opacity. v4's opacity handling for colors is very intuitive, requiring no complex preset color configuration.
3. Theme variable references
bg-brand: We defined@themein the CSS--color-brand. In v4, as long as a CSS variable is defined, Tailwind automatically generates the corresponding utility class (such asbg-brand,text-brand,border-brand), without fiddling in the JS config file.
4. Powerful interactive pseudo-classes
-
**
groupThe difference betweengroup-hover:opacity-100**: -
in
liSet ongroup. -
Set on the delete button
group-hover:opacity-100. -
effect: implements "the delete button only shows when the mouse hovers over this row". Thisparent-child state linkagerequires no JavaScript code.
-
active:scale-95: Uses CSS pseudo-classes to quickly implement button scale feedback on click.
5. Modern borders and ring shadows
focus:ring-2 focus:ring-brand/50: When the input box is focused, useringto create an outer glow border,brand/50ensuring the glow is translucent rather than a rigid solid color.