Vue provides globalProperties on the app instance, an object that can be used to register global properties that can be accessed on any component instance inside the application.
Vue.prototype which is no longer present in Vue 3.import { createApp } from 'vue'
const app = createApp({
/* root component options */
})
app.config.globalProperties.msg = 'hello'
msg can be accessed on any component instance inside the application:
<script>
export default {
mounted() {
console.log(this.msg) // 'hello'
},
}
</script>
If you liked this Vue tip, follow me on Twitter to get notified about new tips, blog posts, and more. Alternatively (or additionally), you can subscribe to my weekly Vue & Nuxt newsletter :
