app.ts onlaunch //获取用户的定位信息
if(this.globalData.loction.lng == 0){
wx.getLocation({
success: async (res: any) => {
mapApi.getUsermap(res.latitude, res.longitude).then((res: any) => {
//全局变量
this.globalData.loction.city = res.data.result.address_component.city;
this.globalData.loction.lat = res.data.result.ad_info.location.lat;
this.globalData.loction.lng = res.data.result.ad_info.location.lng;
//去掉156国家码
let newAdcode = res.data.result.ad_info.city_code.slice(3)
this.globalData.loction.adcode = parseInt(newAdcode) ;
})
}
})
}
index.ts onshow //获取手机导航高度 设置地区
this.setData({
navBarHeigth: app.globalData.menuHeight,
loction:app.globalData.loction.city,
adcode:app.globalData.loction.adcode
})
没有值 要刷新一哈 怎么处理啊!?
。。。还是异步问题。
小程序app与page异步问题的最佳实践? - 微信开放社区 https://developers.weixin.qq.com/community/develop/article/doc/00002ac57208f0e7335d111f156013