Skip to content
Anders Malmgren edited this page Mar 5, 2019 · 2 revisions

Vue Client

Install using unpkg signalr.eventaggregatorproxy.vue as decribed here

Requires the vanilla client library too, so do not forget to install it. Also do not forget to register the event proxy.

<script src="/eventAggregation/events" asp-append-version="true"></script>

Install plugin

Install the Vue plugin by doing

Vue.use(signalR);

Use the plugin

The plugin can be used from any component

new Vue({
    el: '#app',
    data: {
        events: []
    },
    created: function() {
        this.subscribe(MyApp.MyEvent, this.onEvent);        
    },
    methods: {
        onEvent: function(e) {
            this.events.push(e);
        }
    }
});

You can use all of the vanilla client overloads, though the context (this) is marshaled by Vue. This means you do not need to unsubscribe to messages even in a SPA scenario. The Vue-plugin will call unsubscribe on the destroyed event for you.

Publish client side events

Just like the vanilla client you can publish events.

this.publish(new MyClientSideEvent());