Cannot be taken out after the value of the vue sibling component has been passed?

goodsrmT.vue

    data(){
           return {
                form: {
                    token:"",
                },
           }
      }
       mounted(){
             // goodsrm
            var self=this;
            bug.$on("usertoken",function(str){              
                self.form.token=str;
                // console.log(self.form.token) //
                bug.$off("usertoken")
            });
        },

but outside bug.$on ("usertoken", function (str) {}), the value cannot be obtained

Mar.14,2021

mounted is a hook function, and most of the time token is called with a null value.


you can console a tag before taking a value on the outside and assigning a value inside to see whether the value is taken first or assigned first

Menu