In vue's cli scaffolding, the sibling page bus passes parameters why the data is not updated.

Page code before jump

<template>
    <div>
        <button @click="sendMsg">send</button>
    </div>
</template>

<script>
export default {
    name:"demo",
    data: function () {
        return {
            content: "Yin Han"
        } 
    },
    methods: {
        sendMsg: function(){
            this.bus.$emit("msg","sssss")
            this.$router.push("/Demo1")
        }
    }
}
</script>

Page code after jump

<template>
    <div>
        <button>{{getMsg}}</button>
        <button @click="back">back</button>
    </div>
</template>

<script>
export default {
    name: "demo1",
    data: function(){
        return {
            getMsg: "123"
        }
    },
    methods: {
        back: function(){
            this.$router.push("/")
        }
    },
    mounted: function(){
        this.bus.$on("msg",function(msg){
            this.getMsg = msg;
            this.bus.$off("msg")
        })
    }
}
</script>

what you want is to jump to B after clicking send on page A, and then B updates getMsg, through BUS, but the actual operation does not happen, and $on is not triggered the first time you click send, but it will not be triggered until the second time. Refer to how the peer components in Vue use bus to pass values elegantly? but it has not been effectively solved.

Jun.09,2021

listens first and triggers later; however, you do the opposite


for the first time: when the former triggers, the life cycle of the latter has not yet begun, and emit events are not received.
the second time: the life cycle of the latter has begun, event listeners are registered in mounted and have not been destroyed by emit, listeners. Then when the former emit again, the monitor works, so it is thought that it will be triggered after the second time.


it's like you say what I'm going to do this morning, and you don't know what I'm going to do this morning.

Menu