Get current Vue reference

  • Is it possible to get the Current running Vue instance? To listen to the Broadcast events?


    Example of an Broadcasting Event

    Code
    1. // file: app/system/modules/site/app/views/edit.js
    2. //..
    3. methods: {
    4.     save: function() {
    5.         var data = {node: this.node};
    6.         
    7.         this.$broadcast('save', data);
    8.         // ..


    I found the instance is created in app/system/app/vue.js. Or is it initialized anywhere else?

    In window Object in Browser there is a Vue object, but thats not the instance.

    I want to call vue.$on, on the current vue instance or any other listiener method, to listen to those broadcast events published in vue methods.

  • I found a solution. Need to modify some core files.

    Code
    1. // file: /app/system/app/vue.js
    2. // at the start, after "function install (Vue) {" add the following line:
    3. window.$vueInstances = [];
    4. // around line 100, find "fn = function() {" and replace "new Vue()" with
    5. window.$vueInstances.push(new Vue(options));


    Now create a Package and add a script file, in this script file you can reference the instances.

    In my example im listening on $broadcast('save') in app/system/modules/site/app/views/edit.js so my dependencies in script registration are ~node-page.


    Will try to make a pull-request, is there a prefered name for $vueInstances in window?