Transfer values between components at the same level of vue?

implements passing the rm2 value from the rm1 component to the rm2 component
event bus
bugevents.js

import Vue from "vue"

export default new Vue;

rm1.vue

<el-button type="text" @click="sendToken">
      
</el-button>
------------
import bug from "../../../../static/js/bugevents.js";
data(){
        list: {
            token:1
        }
     
},
methods:{
       sendToken(){
        var token = this.list.token;        
        bug.$emit("usertoken",token)
      }
}

rm2.vue

<el-input v-model="token"></el-input>
----------
import bug from "../../../../static/js/bugevents.js";
data(){
    token:""
},
mounted(){
      //rm1
      var self=this;
      bug.$on("usertoken",function(token){
          self.token=token;//datatoken
       })
}
Is

a method error or a code error? I hope all the great gods will give me some advice

Mar.13,2021
What's wrong with

?


sendToken () should be written in methods


found the problem,

mounted(){
      //rm1
      var self=this;
      bug.$on("usertoken",function(token){
          self.token=token; 
          //console.log(self.token),
       })
}
The

value has been taken, but in

bug.$on("usertoken",function(token){
     self.token=token;
 })

cannot be taken out and cannot be assigned to the form,
in data. How to solve this problem?

Menu