Search code examples
javascriptvue.jsdomglobal-variables

How to expose a variable in app.vue globally in vue.js


I am using vuejs to develop a module of my application, i will be getting data which i need to set to a variable ex this.gblData in the App.vue.

I will build the vue application and integrating it into a another application. Is there a way to expose the variable gblData in the parent application.


Solution

  • Yes you can pass this variable thhrough window object:

    // set
    window.gblData = "something";
    // get
    console.log(window.gblData);