Commit 2b3396de authored by 张九刚's avatar 张九刚

优化 Home 组件的状态管理,修复 setHomeInfo 方法中的逻辑顺序,并在 Home.vue 中添加对 homeInfo 的监控,确保初始化信息的正确加载

parent b5b7aa20
...@@ -21,12 +21,13 @@ export const useHomeStore = defineStore('homeInfo', { ...@@ -21,12 +21,13 @@ export const useHomeStore = defineStore('homeInfo', {
* @param {Object} homeInfo * @param {Object} homeInfo
*/ */
setHomeInfo(homeInfo) { setHomeInfo(homeInfo) {
this.homeInfo = homeInfo;
if(homeInfo?.memberId === "not_login"){ if(homeInfo?.memberId === "not_login"){
this.isLogin = false; this.isLogin = false;
}else{ }else{
this.isLogin = true; this.isLogin = true;
} }
this.homeInfo = homeInfo;
}, },
setBabyExistence(babyExistence){ setBabyExistence(babyExistence){
console.log('setBabyExistence', babyExistence); console.log('setBabyExistence', babyExistence);
......
...@@ -191,12 +191,16 @@ export default { ...@@ -191,12 +191,16 @@ export default {
this.statusBarHeight = menuButtonInfo.top; this.statusBarHeight = menuButtonInfo.top;
this.isClickPhoneAuth = false; this.isClickPhoneAuth = false;
this.initHomeInfo();
}, },
watch: { watch: {
homeStore:{ homeStore:{
handler(newVal){ handler(newVal){
this.showRegisterLayer =this.isClickPhoneAuth &&newVal.isLogin && !newVal.babyExistence; this.showRegisterLayer =this.isClickPhoneAuth &&newVal.isLogin && !newVal.babyExistence;
console.log('newVal.homeInfo',newVal.homeInfo);
if(newVal.homeInfo !== null){
this.initHomeInfo();
}
}, },
deep:true, deep:true,
immediate: true immediate: true
...@@ -204,14 +208,10 @@ export default { ...@@ -204,14 +208,10 @@ export default {
}, },
methods: { methods: {
async initHomeInfo() { async initHomeInfo() {
// try{
// await this.homeStore.loadHomeInfo();
// }catch(e){
// console.log('loadHomeInfo error',e);
// }
const { data } = await fetchHomeJSON(); const { data } = await fetchHomeJSON();
console.log('111111111111',data);
if (data) { if (data) {
this.swiperList = data.swiperList; this.swiperList = data.swiperList;
this.vipConfigList = data.vipConfigList; this.vipConfigList = data.vipConfigList;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment