Vue

by FairKing

HTML

<div id="app">
  <p>
    Example 1: {{myGlobalVariable}}
  </p>
  <p>
    Example 2: {{getGlobal('globalVariable')}}
  </p>
</div>

Vue

window.globalVariable = 'I am a global thing';

new Vue({
  el: "#app",
  data: {
  },
  computed: {
		myGlobalVariable: function () {
				return globalVariable;
		},
	},
  methods: {
  	// this could be a mixin
    getGlobal(propertyName) {
    	if (propertyName) {
        //return this.$el.ownerDocument.defaultView[propertyName];
				//return eval(propertyName); // !!! be careful with that, it opens a hole into security
        return window[propertyName];
			} else {
				return null;
			}
    }
  }
})