vue used Bus

Installation @:  npm install vue-bus

. 1
. @ App.js var EventBus = { the install (Vue, Options) { Vue.prototype $ Bus. = New new Vue () } }; Vue.use (EventBus); 2 is then in the assembly. You can use $ emit, $ on, $ off separately to distribute, listen, listen to cancel the event: Methods: { TODO: function () { the this .. $ $ Bus EMIT ( ' todoSth ' , params ); // params are passed parameter // ... } } 3 listener components: // ... Created () { the this $ $ ON Bus (..' TodoSth ' , function ( the params ) { // parameter acquisition and transmission operation // TODO something }) }, // preferably before the destruction of components // clear the event listener beforeDestroy () { the this . Bus $. $ OFF ( ' todoSth ' ); }

 

Guess you like

Origin www.cnblogs.com/huanhuan55/p/11367526.html