--- title: Composition and Options API Can Coexist in Same Component impact: LOW impactDescription: Understanding coexistence helps gradual migration and library integration type: best-practice tags: [vue3, composition-api, options-api, migration, interoperability] --- # Composition and Options API Can Coexist in Same Component **Impact: LOW** - Vue 3 allows using both APIs in the same component via the `setup()` option. This is useful for gradual migration of existing Options API codebases or integrating Composition API libraries into Options API components. However, this should be a transitional pattern. For new code, pick one API style and stick with it. ## Task Checklist - [ ] Only mix APIs when migrating existing code or integrating libraries - [ ] Use `setup()` option (not ` ``` **Important Limitations:** ```javascript export default { data() { return { optionsData: 'hello' } }, setup(props, context) { // WRONG: 'this' is NOT available in setup() console.log(this.optionsData) // undefined! // CORRECT: Access props and context via parameters console.log(props.someProp) console.log(context.attrs) console.log(context.emit) // To access Options API data from setup, // you generally can't - they're in separate scopes // The Options API CAN access setup's returned values though return { /* ... */ } } } ``` ## When to Use This Pattern - **Migrating large codebase**: Migrate piece by piece without rewriting everything - **Integrating libraries**: Some libraries (like VueUse) are Composition API only - **Team transition**: Let teams learn Composition API gradually - **Options API components that need one composable**: Quick integration ## When NOT to Use This Pattern - **New components**: Just use `