Performance: Composable vs mixin comparison
MEDIUM IMPACT
This affects page load speed and interaction responsiveness by influencing JavaScript execution and component rendering.
import { ref, onMounted } from 'vue'; export function useCounter() { const count = ref(0); function increment() { count.value++; } onMounted(() => { console.log('Composable mounted'); }); return { count, increment }; } export default { setup() { const { count, increment } = useCounter(); return { count, increment }; } }
const myMixin = { created() { console.log('Mixin created'); }, methods: { sharedMethod() { console.log('Shared logic'); } } } export default { mixins: [myMixin], data() { return { count: 0 }; }, methods: { increment() { this.count++; } } }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Mixin | No direct DOM ops, but causes duplicated reactive setups | Multiple reactivity recalculations | Minimal paint impact | [X] Bad |
| Composable | No direct DOM ops, single reactive setup per usage | Single reactivity recalculation | Minimal paint impact | [OK] Good |