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.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b375b5-2b804.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b375b5-2b804.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?