微信小程序函數執行順序問題


我在微信小程序中自定義兩個函數,一個是獲取位置,一個是獲取天氣,
在Page中

Page({
    getLocalCity: function(){},
    getWeather: function(){},
})

這樣定義函數的,
調用時這樣的:

Page({
    onLoad:function(){
        this.getLocalCity();
        this.getWeather();
    }
})

在onLoad的時候調用,但我無論怎么寫,getWeather()函數都是執行在前,這是為什么呢?

return 一個 Promise 然后鏈式調用。

    getLocalCity() {
        return new Promise(resolve => {
            wx.request({
                url: "",
                success: res => {
                    // ...
                    return resolve();
                },
            })
        });
    },
    getWeather(){
      // ...  
    },
    onLoad() {
        this.getLocalCity().then(result => {
            this.getWeather();
        });
    }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM