Text Inputs
A text input is a one-line box for short text. It uses v-model to hold what a person types.
A text input
This box holds one short line of text.
<input type="text" v-model="name">A textarea
This box holds longer text.
<textarea v-model="bio"></textarea>Two boxes, two refs
Each box links to its own ref.
const name = ref('')
const bio = ref('')Example
<script setup>
import { ref } from 'vue'
const name = ref('')
const bio = ref('')
</script>
<template>
<div>
<label>Name <input type="text" v-model="name"></label>
<label>Bio <textarea v-model="bio"></textarea></label>
<p>Name: {{ name }}</p>
<p>Bio: {{ bio }}</p>
</div>
</template>Key points
- A text input is a one-line box for a short answer, like a name.
- The type attribute with the value text marks the box as a text input.
- A textarea is a bigger box for longer text, like a short bio.
- v-model works on a textarea in the same way as on a text input.
- Each box needs its own ref, so each answer stays separate.
In this example, name and bio are refs that start as empty strings. The text input links to name, and the textarea links to bio. Two paragraphs show the two answers. Both boxes start empty, so both paragraphs start empty. Typing Ada and Hi fills the two paragraphs with those words.
Note
Both boxes start empty here, so the page shows two empty boxes.
Try it Yourself
Edit the code, then press Run.
Running is simulated
Exercise
Which box fits a long answer like a short bio?