Back
VueHardNew

What is the difference between `app.config.globalProperties` and `provide`/`inject` for sharing utilities app-wide?

Implicit global 'this' access vs explicit opt-in injection

Ideal Answer

  • app.config.globalProperties: Attaches a property to every component instance implicitly, accessible via this in the Options API (e.g., this.$http). It's convenient but implicit — it's not obvious where a given global property comes from, and it doesn't work well with <script setup>/Composition API, which doesn't use this.

  • provide/inject: Requires explicit opt-in via inject('key') in each consuming component, making dependencies traceable, and works naturally with the Composition API.

For new Vue 3 codebases, especially ones using <script setup>, provide/inject (or composables) is the preferred pattern over global properties.