--- title: defineModel Default Value Can Cause Parent-Child Desync impact: HIGH impactDescription: Default values in defineModel don't sync back to parent, causing state inconsistency type: capability tags: [vue3, v-model, defineModel, components, props, two-way-binding] --- # defineModel Default Value Can Cause Parent-Child Desync **Impact: HIGH** - When using `defineModel()` with a default value and the parent doesn't provide a value, the parent and child components will have different values. The parent's ref stays `undefined` while the child uses the default, breaking the two-way binding contract. This subtle bug can cause confusing behavior where the parent component shows one value while the child shows another, and updates may not propagate correctly. ## Task Checklist - [ ] Always provide initial values from the parent when using v-model - [ ] Don't rely on defineModel defaults as the primary source of truth - [ ] If defaults are needed, also set them in the parent component - [ ] Test components with and without v-model props provided **Problem - Parent and child out of sync:** ```html ``` ```html ``` **Solution 1 - Always provide initial value from parent:** ```html ``` **Solution 2 - Child emits default on mount (if parent control not possible):** ```html ``` **Solution 3 - Use required prop or explicit undefined handling:** ```html ``` **Best Practice - Document expected initial values:** ```html ``` ## Reference - [Vue.js Component v-model](https://vuejs.org/guide/components/v-model.html) - [Vue School - defineModel Guide](https://vueschool.io/articles/vuejs-tutorials/v-model-and-definemodel-a-comprehensive-guide-to-two-way-binding-in-vue-js-3/)