diff --git a/src/stores/lastImg.js b/src/stores/lastImg.js index 229bbad..9791d29 100644 --- a/src/stores/lastImg.js +++ b/src/stores/lastImg.js @@ -7,10 +7,32 @@ export const useLastImgStore = defineStore('lastImg', { actions: { setLastImgUrl(lastImgUrl) { this.imgUrl = lastImgUrl + + // 添加持久化存储 + if (lastImgUrl) { + localStorage.setItem('lastImgUrl', lastImgUrl) + } else { + localStorage.removeItem('lastImgUrl') + } + }, + + // 添加初始化方法 + initFromStorage() { + const stored = localStorage.getItem('lastImgUrl') + if (stored) { + this.imgUrl = stored + } }, clearCache() { this.imgUrl = null + localStorage.removeItem('lastImgUrl') }, }, + + // 可选:添加持久化插件配置 + persist: { + key: 'lastImgUrl', + storage: localStorage, + }, }) diff --git a/src/views/Wallet/CashOut/KYC.vue b/src/views/Wallet/CashOut/KYC.vue index f8c863e..03db8a1 100644 --- a/src/views/Wallet/CashOut/KYC.vue +++ b/src/views/Wallet/CashOut/KYC.vue @@ -200,8 +200,10 @@ import { storeToRefs } from 'pinia' const { t, locale } = useI18n() const router = useRouter() -const lastImgStore = useLastImgStore() //获取图片缓存 -const { imgUrl: lastImgUrl } = storeToRefs(lastImgStore) //国家信息 +const lastImgStore = useLastImgStore() +// 初始化时从 localStorage 恢复数据 +lastImgStore.initFromStorage() +const { imgUrl: lastImgUrl } = storeToRefs(lastImgStore) //获取图片缓存 // 监听语言变化并设置文档方向 locale.value && setDocumentDirection(locale.value)