<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>总线/Bus/观察者模式/发布订阅模式</title> <script src="js/vue.js" type="text/javascript" charset="utf-8"></script> </head> <body> <div id="root"> <child concent="Dell"></child> <child concent="Lee" ></child> </div> <script> Vue.prototype.bus=new Vue()//在VUE里添加一个属性 Vue.component('child',{ data:function(){ return{ selfConcent:this.concent } }, props:{ concent:String }, template:'<div @click="handleClick">{{selfConcent}}</div>', methods:{ handleClick:function(){ this.bus.$emit('change',this.selfConcent) } }, mounted:function(){ var this_=this this.bus.$on("change",function(msg){ this_.selfConcent=msg }) } }) var vm=new Vue({ el:"#root" }) </script> </body> </html>