You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+30-1Lines changed: 30 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -39,14 +39,43 @@ Vue.use(EventManager)
39
39
methods: {
40
40
eventHandler(payload) {
41
41
console.log('Yay, events work!', payload);
42
+
},
43
+
eventHandlerOnce(payload) {
44
+
console.log('This will be called just once!');
42
45
}
43
46
},
44
47
created() {
45
48
this.$events.on('test', this.eventHandler);
46
-
this.$events.once('test', () =>console.log('This will be called just once!'));
49
+
this.$events.once('test', this.eventHandlerOnce);
47
50
},
48
51
beforeDestroy() {
49
52
this.$events.off('test', this.eventHandler);
53
+
this.$events.off('test', this.eventHandlerOnce);
54
+
}
55
+
```
56
+
57
+
P.S.: Alternative way to set your event handlers is through the `on` and `once` Vue constructor options. In that way you shouldn't worry about removing event handlers on `beforeDestroy`.
0 commit comments