标题uni-app中使用异步请求
问题:
如果直接在代码中使用异步请求
在下方无法立即获取到实时数据
解决办法:
例如:使用uni-app的获取位置的请求uni.getLocation
1,封装uni.getLocation请求
async getL() {
var Location
return new Promise((resolve, reject) => {
uni.getLocation({
type: 'wgs84',
success: function(res) {
Location = res.longitude + "," + res.latitude
resolve(Location)
}
})
})
},
2,然后在需要使用的地方调用即可
async getlist() {
await this.getL().then((res) => {
this.Location =res
})
}