1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | const broadcast = (componentName, eventName, params) => {
|
18 | this.$children.forEach(child => {
|
19 | const name = child.$options.name;
|
20 | if (name === componentName) {
|
21 | child.$emit.apply(child, [eventName].concat(params));
|
22 | } else {
|
23 |
|
24 | broadcast.apply(child, [componentName, eventName].concat([params]));
|
25 | }
|
26 | });
|
27 | }
|
28 | export default {
|
29 | methods: {
|
30 | dispatch(componentName, eventName, params) {
|
31 | let parent = this.$parent || this.$root;
|
32 | let name = parent.$options.name;
|
33 |
|
34 | while (parent && (!name || name !== componentName)) {
|
35 | parent = parent.$parent;
|
36 | if (parent) name = parent.$options.name;
|
37 | }
|
38 | if (parent) parent.$emit.apply(parent, [eventName].concat(params));
|
39 | },
|
40 | broadcast(componentName, eventName, params) {
|
41 | broadcast.call(this, componentName, eventName, params);
|
42 | }
|
43 | }
|
44 | }; |
\ | No newline at end of file |