Text Models
Part of the Fundamentals section of Coddy's Vue journey. Lesson 16 of 55.
A text input can share a ref with a paragraph through v-model. Typing Mina into this field changes the ref and the displayed greeting together.
const visitor = ref('');
// <input v-model="visitor">
// <p>Welcome, {{ visitor }}</p>The binding works in both directions: user input updates state, and assigning the ref updates the input. Start text models with a string. A plain :value binding displays state but does not itself listen for edits.
Challenge
EasyBind input#name to a string ref starting empty. Show Hello, followed by the current input in p#result. Editing or clearing the field must update the greeting.
Try it yourself
<!doctype html><html><head><meta charset="UTF-8"><title>Vue practice</title></head><body><div id="app"></div><script type="module" src="./main.js"></script></body></html>This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
2Reactive State
Reactive RefsUpdating Refs in ScriptEvent Handler ArgumentsReactive ObjectsRecap: Reactive State5Conditions and Lists
Conditional BranchesShow without UnmountingRendering ListsStable List IdentityRecap: Conditions8Component Communication
Emitting EventsEvent PayloadsLifting Shared StateDefault and Named SlotsRecap: Shared Panel11Project: Community Board
Board StructureAdding Community Tasks