Performance: v-model with text inputs
This affects input responsiveness and rendering speed during user typing.
<template> <input type="text" :value="text" @input="onInput" /> </template> <script setup> import { ref } from 'vue' const text = ref('') function onInput(event) { text.value = event.target.value } </script>
<template> <input type="text" v-model="text" /> </template> <script setup> import { ref } from 'vue' const text = ref('') </script>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| v-model on text input (default) | 1 update per keystroke | 1 reflow per keystroke | 1 paint per keystroke | [X] Bad |
| Manual input event with debounced update | 1 update per debounce interval | 1 reflow per debounce interval | 1 paint per debounce interval | [OK] Good |
v-model do when used on a text input in Vue?username using v-model?v-model="username" on the input element.const app = Vue.createApp({
data() {
return { message: 'Hello' };
}
});
// Template:
// <input v-model="message" type="text" />
// <p>{{ message }}</p>message data property immediately due to two-way binding.{{ message }}, so it shows the updated value typed by the user.<input v-model="userName" type="text" />
<p>User: {{ username }}</p>v-model="userName" but paragraph uses {{ username }} with different casing.userName and username as different properties, so paragraph does not update.firstName and lastName using v-model. You also want to display the full name live as the user types. Which Vue template snippet correctly achieves this?Pass the test and this pattern moves unknown