1. What is the difference between Options API and Composition API in Vue 3?
❓ Context: Compare Options API and Composition API regarding code organization, TypeScript support, and reusability.
Vue 3 provides two programming styles for writing components:
Options API ('data', 'methods', 'computed', 'mounted'):
Composition API ('<script setup>' + 'ref', 'reactive', 'computed'):
Best Practice (2026):
Use '<script setup>' (Composition API) by default for modern Vue 3 projects.
<!-- Options API (Vue 2 style) -->
<script>
export default {
data() { return { count: 0 }; },
methods: { increment() { this.count++; } }
}
</script>
<!-- Composition API with <script setup> (Vue 3 standard) -->
<script setup>
import { ref } from 'vue';
const count = ref(0);
const increment = () => count.value++;
</script>
<template>
<button @click="increment">Count: {{ count }}</button>
</template>Composition API with <script setup> organizes code by logical features, improves TypeScript inference, and enables composables.