diff --git a/pages/discount/discount.vue b/pages/discount/discount.vue index 3b2d182..7f57d56 100644 --- a/pages/discount/discount.vue +++ b/pages/discount/discount.vue @@ -56,14 +56,21 @@ export default { } }, onLoad() { - const loc = uni.getStorageSync('lng') && uni.getStorageSync('lat') - ? { lng: uni.getStorageSync('lng'), lat: uni.getStorageSync('lat') } - : null - if (loc) { - this.lng = loc.lng - this.lat = loc.lat + const hasLoc = uni.getStorageSync('lng') && uni.getStorageSync('lat') + if (hasLoc) { + this.lng = uni.getStorageSync('lng') + this.lat = uni.getStorageSync('lat') + this.loadList() + } else { + // xuchao: 定位仅在首页触发过,直接进本页无缓存时主动获取一次,保证距离列可展示 + import('@/common/location.js').then(module => module.default.getLocation()) + .then(({ lng, lat }) => { + this.lng = lng + this.lat = lat + }) + .catch(() => {}) + .finally(() => this.loadList()) } - this.loadList() }, methods: { loadList() {