微信小程序函数执行顺序问题

我在微信小程序中自定义两个函数,一个是获取位置,一个是获取天气,
在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();
});
}

微信小程序函数执行顺序问题

原文:https://www.cnblogs.com/panziwen/p/15037909.html

以上是微信小程序函数执行顺序问题的全部内容。
THE END
分享
二维码
)">
< <上一篇
下一篇>>