I have a javascript variable which I want to pass globally to Vue components upon instantiation thus either each registered component has it as a property or it can be accessed globally.
Note:: I need to set this global variable for vuejs as a READ ONLY property
You can use mixin and change var in something like this.
Just Adding Instance Properties
For example, all components can access a global
appName
, you just write one line code:Vue.prototype.$appName = 'My App'
$
isn't magic, it's a convention Vue uses for properties that are available to all instances.Alternatively, you can write a plugin that includes all global methods or properties.
You can use a Global Mixin to affect every Vue instance. You can add data to this mixin, making a value/values available to all vue components.
To make that value Read Only, you can use the method described in this stackoveflow answer.
Here is an example: