
Vue 3 Has a Free API — Here's How to Build Reactive Apps with Composition API
Vue 3 introduces the Composition API — a flexible way to organize component logic. Combined with script setup and reactivity primitives, it makes building complex UIs intuitive. Getting Started npm create vue@latest my-app cd my-app npm install && npm run dev Composition API Basics < script setup lang= "ts" > import { ref , computed , onMounted } from " vue " ; const count = ref ( 0 ); const doubled = computed (() => count . value * 2 ); function increment () { count . value ++ ; } onMounted (() => { console . log ( " Component mounted! " ); }); </ script > < template > <p> Count: {{ count }} (doubled: {{ doubled }} ) </p> <button @ click= "increment" > +1 </button> </ template > Reactive State < script setup > import { reactive , toRefs } from " vue " ; const state = reactive ({ todos : [], filter : " all " , newTodo : "" }); const { todos , filter , newTodo } = toRefs ( state ); function addTodo () { state . todos . push ({ id : Date . now (), text : state . newTodo , done : false })
Continue reading on Dev.to Webdev
Opens in a new tab


