Commit 9952cc4c by liimin

refactor(boutique): 优化 BoutiqueHomePanel 组件的数据加载逻辑

- 添加 .qoder 到 .gitignore 文件,防止意外提交
- 使用 onMounted 替代首次加载的 onShow,避免重复请求
- 新增 _skipNextShow 标志防止 onShow 紧随 onMounted 时的重复加载
- 保留 onShow 处理页面返回时的数据刷新场景
- 优化注释,明确首次加载和返回刷新逻辑区别
1 parent 35adf822
......@@ -6,3 +6,4 @@
node_modules
assets/images/sprite.png
assets/css/sprite.scss
/.qoder
......@@ -55,7 +55,7 @@
import type { BoutiqueLogic } from "@/pages/boutique/useBoutiqueLogic.uts";
import { useBoutiqueLogic } from "@/pages/boutique/useBoutiqueLogic.uts";
import { ComponentPublicInstance, computed, nextTick, onShow, ref } from "vue";
import { ComponentPublicInstance, computed, nextTick, onMounted, onShow, ref } from "vue";
import CenterPopup from "@/components/CenterPopup.uvue";
import PackageDetailPopup from "@/pages/boutique/components/PackageDetailPopup.uvue";
......@@ -73,14 +73,29 @@ const props = defineProps<{
const logic: BoutiqueLogic = (props.logic != null) ? props.logic : useBoutiqueLogic();
/** 组件级 onShow:每次页面展示时刷新数据(initIfNeeded 有内部防重复守卫) */
/**
* 数据加载:onMounted 覆盖首次加载 + v-if 重建(横竖屏切换);
* onShow 覆盖用户从其他页面返回时的刷新场景。
*/
let _initialized = false;
onShow(() => {
let _skipNextShow = false;
function _loadData(): void {
if (!_initialized) {
_initialized = true;
void logic.initIfNeeded();
}
void logic.getBoutiquePackageList();
}
onMounted(() => {
_loadData();
_skipNextShow = true; // onShow 紧随 onMounted 触发时去重,避免首次加载双请求
});
onShow(() => {
if (_skipNextShow) {
_skipNextShow = false;
return;
}
_loadData();
});
/** 模板里对嵌套 ComputedRef 的解包因端而异,用本地 computed 收口 */
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!