<template> <div class="a"> <h2>this is A</h2> <span>{{ msg }}</span> </div> </template> <script> import Bus from '../Tools/EventBusTool'; export default { data(){ return{ msg:'' } }, created(){ Bus.$on('sent',(msg) =>{ this.msg=msg }) } } </script> <style> .a{ border: 100px; background-color: aqua; } </style>
<template> <div class="b"> <h2>this is B</h2> <button @click="sent">sent</button> </div> </template> <script> import Bus from '../Tools/EventBusTool'; export default { methods:{ sent(){ Bus.$emit('sent','需要发送的消息') } } } </script> <style scoped> .b{ border: 100px; } </style>
eventBusTool import Vue from "vue"; const Bus=new Vue() export default Bus
标签:vue,Bus,访问,export,msg,import,平级,sent From: https://www.cnblogs.com/wllovelmbforever/p/17825810.html