import Vue from'vue'const Bus =newVue()exportdefault Bus
model/form.vue
<template><divstyle="background: pink;">
form组件中{{total}}
</div></template><script>import Bus from'./bus.js'exportdefault{data(){return{
total:0}},created(){
Bus.$on('total', val =>{this.total = val
})}}</script>
model/table.vue
<template><divstyle="display:flex;background: green;">
table组件中<el-inputv-model="total"></el-input></div></template><script>import Bus from'./bus.js'exportdefault{data(){return{
total:0}},
watch:{total(val){
Bus.$emit('total',val)}},//在离开当前页面前要注销掉,要不然会出现很严重的bugbeforeDestory(){
Bus.$emit('total')}}</script>