Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Vue 3 debugging reference for reactivity issues, computed errors, watcher bugs, async failures, and SSR hydration problems.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
reference/v-model-ignores-html-attributes.md
1---2title: v-model Ignores Initial HTML Attributes3impact: HIGH4impactDescription: v-model ignores value, checked, and selected HTML attributes - initial state must be set in JavaScript5type: capability6tags: [vue3, v-model, forms, input, checkbox, select, initialization]7---89# v-model Ignores Initial HTML Attributes1011**Impact: HIGH** - Setting initial values via HTML `value`, `checked`, or `selected` attributes has no effect when using v-model. The form will appear empty or in an unexpected state, confusing users and potentially causing data loss.1213Vue's v-model always treats the bound JavaScript state as the single source of truth. Any initial attributes in the HTML are completely ignored. This is a common mistake when migrating from plain HTML forms or when copying HTML templates.1415## Task Checklist1617- [ ] Never rely on HTML `value`, `checked`, or `selected` attributes when using v-model18- [ ] Always declare initial values in JavaScript using `ref()` or `reactive()`19- [ ] When migrating plain HTML forms to Vue, move all default values to JavaScript state20- [ ] Audit existing forms for hardcoded HTML default values that may be silently ignored2122**Incorrect:**23```html24<script setup>25import { ref } from 'vue'2627const username = ref('') // Empty!28const isSubscribed = ref(false) // Not checked!29const country = ref('') // No default selection!30</script>3132<template>33<!-- WRONG: These HTML attributes are completely ignored -->34<input v-model="username" value="default_user">3536<input type="checkbox" v-model="isSubscribed" checked>3738<select v-model="country">39<option value="us" selected>United States</option>40<option value="uk">United Kingdom</option>41</select>42</template>43```4445**Correct:**46```html47<script setup>48import { ref } from 'vue'4950// CORRECT: Set initial values in JavaScript51const username = ref('default_user')52const isSubscribed = ref(true)53const country = ref('us')54</script>5556<template>57<!-- HTML attributes not needed - JavaScript state controls everything -->58<input v-model="username">5960<input type="checkbox" v-model="isSubscribed">6162<select v-model="country">63<option value="us">United States</option>64<option value="uk">United Kingdom</option>65</select>66</template>67```6869```javascript70// Options API equivalent71export default {72data() {73return {74username: 'default_user',75isSubscribed: true,76country: 'us'77}78}79}80```8182## Reference83- [Vue.js Form Input Bindings](https://vuejs.org/guide/essentials/forms.html)84