Question presented to candidate:
"Our codebase has older Vue components written with data, methods and computed, and newer ones using <script setup>. Explain what the Composition API is, how it differs from the Options API, and which one you would pick for new code."
What a strong answer should cover:
- The Options API organises a component by option type (
data,computed,watch,methods, lifecycle options) and reaches state throughthis. - The Composition API organises it by feature:
ref,reactive,computed,watchandonMountedare imported functions called insidesetup()or<script setup>. - Both sit on the same reactivity system; the Options API is implemented on top of it, so they are equally capable and can be mixed in one component.
- The real wins are logic reuse through composables, better TypeScript inference (no
this), and code that groups by concern in large components. - Trade-offs: the Options API is more guided for beginners; the Composition API needs discipline (
.value, organising code yourself). - A build can drop the Options API code with the
__VUE_OPTIONS_API__flag when no component uses it.
Clarifying questions expected:
- "Is this for new components only, or are we considering migrating existing ones?"
- "Do we use TypeScript? That changes how strong the case is."
Code / implementation expected: Optional β the same small feature in both styles, ideally showing this versus ref and .value.