
How defineModel simplifies v-model in custom Vue components
In this article, I show a practical use case: a custom modal component where defineModel controls visibility — no props , no emit , no boilerplate. TL;DR: defineModel replaces the traditional modelValue + update:modelValue pattern with a single reactive binding. When Vue introduced defineModel , it looked nice in theory, but I wanted to see how it feels in a real component. So instead of a contrived counter example, I tried it with something we all build at some point: a modal. The modal itself uses the native <dialog> element, but that’s not the main point here. The interesting part is how clean the component API becomes with defineModel . The Goal I want to be able to write this: <MyModal v-model= "isModalOpen" /> …without writing: modelValue prop update:modelValue emit extra sync logic Just v-model and done. Demo 👉 Live demo (StackBlitz) App.vue < script setup > import { ref } from ' vue ' ; import MyModal from ' ./components/MyModal.vue ' ; const isModalOpen = ref ( false ); </ scr
Continue reading on Dev.to Tutorial
Opens in a new tab

