'a'
mh-two-thousand-and-two
2024-04-12 44d2c92345cd156a59fc327b3060292a282d2893
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// 暂不提供通知所有
// function broadcast (componentName, eventName, ...params) {
//   this.$children.forEach(child => {
//     const name = child.$options.name && child.$options.name.substr(1)
//     if (~componentName.indexOf(name)) {
//       child.$emit.apply(child, [eventName].concat(params))
//     } else {
//       broadcast.apply(child, [componentName, eventName].concat([params]))
//     }
//   })
// }
function broadcast (componentName, eventName, ...params) {
  const children = this.$children
  const len = children.length
  for (let i = 0; i < len; i++) {
    const child = children[i]
    const name = child.$options.name && child.$options.name.substr(4)
    if (~componentName.indexOf(name)) {
      child.$emit.apply(child, [eventName].concat(params))
      return false
    } else {
      if (broadcast.apply(child, [componentName, eventName].concat([params])) === false) {
        return false
      }
    }
  }
}
export default {
  methods: {
    $dispatch (componentName, eventName, ...params) {
      if (typeof componentName === 'string') {
        componentName = [componentName]
      }
      let parent = this.$parent || this.$root
      let name = parent.$options.name && parent.$options.name.substr(4)
 
      while (parent && (!name || !~componentName.indexOf(name))) {
        parent = parent.$parent
 
        if (parent) {
          name = parent.$options.name && parent.$options.name.substr(4)
        }
      }
      if (parent) {
        parent.$emit.apply(parent, [eventName].concat(params))
      }
    },
    $broadcast (componentName, eventName, ...params) {
      if (typeof componentName === 'string') {
        componentName = [componentName]
      }
      broadcast.apply(this, [componentName, eventName].concat(params))
    }
  }
}