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 acces
You can use mixin and change var in something like this.
// This is a global mixin, it is applied to every vue instance
Vue.mixin({
data: function() {
return {
globalVar:'global'
}
}
})
Vue.component('child', {
template: "In Child: {{globalVar}}"
});
new Vue({
el: '#app',
created: function() {
this.globalVar = "It's will change global var";
}
});
In Root: {{globalVar}}