-
Notifications
You must be signed in to change notification settings - Fork 37
Vue Client
Anders Malmgren edited this page Mar 5, 2019
·
2 revisions
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 the Vue plugin by doing
Vue.use(signalR);
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.
Just like the vanilla client you can publish events.
this.publish(new MyClientSideEvent());