Skip to content

Instantly share code, notes, and snippets.

@ronokdev
Last active March 28, 2018 20:21
Show Gist options
  • Save ronokdev/cc69b608c9e1b361f5f55e1517f1d22a to your computer and use it in GitHub Desktop.
Save ronokdev/cc69b608c9e1b361f5f55e1517f1d22a to your computer and use it in GitHub Desktop.
Set a Global Vue Instance
::: RefUrl → https://vuejs.org/v2/cookbook/adding-instance-properties.html#Base-Example
::: Set Global instance in index.js (src/router)
→ Vue.prototype.$VariableName = Value;
→ Example : Vue.prototype.$_serverName = window.location.hostname;
→ $ is a convention Vue uses for properties that are available to all instances.
::: Access it from any Vue Components
→ export default {
created:function () {
console.log(this.$_serverName);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment