Categories
Vue Answers

How to apply global variables to Vue.js?

Spread the love

Sometimes, we want to apply global variables to Vue.js.

In this article, we’ll look at how to apply global variables to Vue.js.

How to apply global variables to Vue.js?

To apply global variables to Vue.js, we can add our global variables into the Vue prototype.

For instance, we write

Vue.prototype.$appName = 'App'

to add the $appName global variable that we can access in all components in the app with

this.$appName

Conclusion

To apply global variables to Vue.js, we can add our global variables into the Vue prototype.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *