-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevents.js
37 lines (32 loc) · 949 Bytes
/
events.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
'use strict';
function plugin(Vue) {
if (plugin.installed) {
return;
}
var events = new Vue({
methods: {
fire: function fire(name) {
var data = arguments.length <= 1 || arguments[1] === undefined ? null : arguments[1];
this.emit(name, data);
},
emit: function emit(name) {
var data = arguments.length <= 1 || arguments[1] === undefined ? null : arguments[1];
this.$emit(name, data);
},
listen: function listen(name, cb) {
this.on(name, cb);
},
on: function on(name, cb) {
this.$on(name, cb);
}
}
});
Object.defineProperty(Vue.prototype, '$events', {
get: function get() {
return events;
}
});
}
if (typeof window !== 'undefined' && window.Vue) {
window.Vue.use(plugin);
}