Event Bus bus transfer value resolved between brothers components

Verbatim https://www.dazhuanlan.com/2019/08/25/5d625951eff92/


Event Bus bus transfer value resolved between brothers components

practical use:

A packageBus.js

1
2
3
Import View from  'view' 
const Bus = new View ()
Export default Bus

Introduced at the component calls

Component one:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
import Bus from './Bus'

export default {
data() {
return {
.........
}
},
methods: {
....
Bus.$emit('log', 120)
},

}

Component II:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
import Bus from './Bus'

export default {
data() {
return {
.........
}
},
mounted () {
Bus.$on('log', content => {
console.log(content)
});
}
}

Guess you like

Origin www.cnblogs.com/petewell/p/11408835.html