Cross-reference of methods in Vue

  1. methods cross-reference problem in Vue. Return undefined
  2. the code is as follows

    methods:{
    funca: function(){
        let token = this.$http.post(xxx);// posttoken
        alert("cc " + token);
        renturn token;
    }
    funcb: function(){
        let token = this.funca();
        //let token = this.$options.methods.getToken.bind(this)();
        //tokenundefined
        //token
        this.$http.get(xxx).then(function (res){
            alert("aa")
        },function(err){
            alert("bb")
        });
    }};
    mounted():{
    this.funcb();

    }

3. The result of the run is that the code that pops up the token, will not execute to

because it cannot get the aa.
  • Pop up bb first
  • then pop up cc

4. Why is the funca, called first and then executed?

Mar.03,2021

funa=function(){
    let token =Promise.resolve(1).then(dd=>dd)
    alert("cc " + token);
    return token;
}
funcb=function(){
    let token = funa();
    Promise.reject(1).then(function (res){
        alert("aa")
    },function(err){
        alert("bb")
    });
};

funcb()

first of all, your let token = this.$http.post (xxx); is wrong. Here token is a Promise object. I simulated it according to your logic. There is no case of bb and then cc, and your return is wrong, not renturn

.
Menu