fix: 折扣页无定位缓存时主动获取定位,保证商铺距离展示

This commit is contained in:
jacobxu666
2026-09-02 22:43:35 +08:00
parent 742973b31b
commit 4ac98a30fb
+14 -7
View File
@@ -56,14 +56,21 @@ export default {
} }
}, },
onLoad() { onLoad() {
const loc = uni.getStorageSync('lng') && uni.getStorageSync('lat') const hasLoc = uni.getStorageSync('lng') && uni.getStorageSync('lat')
? { lng: uni.getStorageSync('lng'), lat: uni.getStorageSync('lat') } if (hasLoc) {
: null this.lng = uni.getStorageSync('lng')
if (loc) { this.lat = uni.getStorageSync('lat')
this.lng = loc.lng
this.lat = loc.lat
}
this.loadList() 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())
}
}, },
methods: { methods: {
loadList() { loadList() {