Menu
CoddyTech

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 icon

Challenge

Easy

Bind 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>
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals