From e99dbc2245b0c5530bbbea74ee4b7b05c73dd1d9 Mon Sep 17 00:00:00 2001 From: lcc <805383944@qq.com> Date: Tue, 14 Oct 2025 20:52:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=AE=9A=E4=BD=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/CityChooseList.vue | 6 ++++-- src/pages/Home.vue | 7 +++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/components/CityChooseList.vue b/src/components/CityChooseList.vue index 76eabae..2f0994b 100644 --- a/src/components/CityChooseList.vue +++ b/src/components/CityChooseList.vue @@ -101,8 +101,10 @@ export default { cityName: result.data.cityName, cityId: result.data.cityId }; - localStorage.setItem('cityInfo', JSON.stringify(result.data)); - localStorage.setItem('userLocation', JSON.stringify({ ...location, time: new Date().getTime() })); + // localStorage.setItem('cityInfo', JSON.stringify(result.data)); + // localStorage.setItem('userLocation', JSON.stringify({ ...location, time: new Date().getTime() })); + setCookie('cityInfo', JSON.stringify(result.data),1); + setCookie('userLocation', JSON.stringify({...location, time: new Date().getTime()},1)); userStore.setCity(result.data); this.$emit('cityItem',{ cityName: result.data.cityName, diff --git a/src/pages/Home.vue b/src/pages/Home.vue index fc76354..0f79a46 100644 --- a/src/pages/Home.vue +++ b/src/pages/Home.vue @@ -317,13 +317,16 @@ const getCurrentLocation = async () => { let location = getCookie('userLocation') || await WechatLocation.getLocation('gcj02'); console.log('当前位置:', location); const userStore = useUserStore(); - // 解析位置获取城市信息 - if (!location || !location.latitude || !location.longitude) { + if(!location || !location.latitude || !location.longitude){ + //删除cookie + setCookie('cityInfo', null); + //重新赋值location location = { latitude: '24.479627', longitude: '118.08891' }; } + // 解析位置获取城市信息 if (location && location.latitude && location.longitude) { // if(localStorage.getItem('cityInfo')){ // 修改为从 cookie 获取城市信息