Performance: Using stores in components
MEDIUM IMPACT
Using stores in Vue components affects how state updates trigger component re-renders and how efficiently data flows through the app.
import { useStore } from 'vuex'; import { computed } from 'vue'; export default { setup() { const store = useStore(); const count = computed(() => store.getters['getCount']); return { count }; } }
import { useStore } from 'vuex'; import { computed } from 'vue'; export default { setup() { const store = useStore(); const count = computed(() => store.state.count); return { count }; } }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Direct store state access in many components | High (many reactive dependencies) | High (many re-renders) | High (many paints) | [X] Bad |
| Using selective getters and mutations | Low (minimal reactive dependencies) | Low (targeted re-renders) | Low (fewer paints) | [OK] Good |