The two brothers of vue passed the value. Why didn't it work when component a was clicked for the first time? Do you need to go to the b component and then return the a component to pass the value?

vue is passed by two brothers. Why didn"t it work when component a was clicked for the first time? Do you need to go to the b component and then return the a component to pass the value?

clipboard.png

onetwo

clipboard.png

I created a js file

   import Vue from "vue";  
   
   export default new Vue();  

in the one component

 <div>
A:

  <span>{{elementValue}}</span>
  <input type="button" value="" @click.stop.prevent="elementByValue($event)">
  </div>
  
   import Bus from "../assets/eventBus.js"
    elementByValue: function () {
    Bus.$emit("getTarget","123")
  }
  

in the two component

 import Bus from "../assets/eventBus.js"
 
  Bus.$on("getTarget", target => {  
            console.log(target);  
        }); 
   

the first click in the one component has no effect. You have to go to the two component and then return to the one component. How to solve this situation?

Mar.02,2021

write the one in the two component in your new Vue js

.
Menu