feat(KYC页面): pinia使用持久化
This commit is contained in:
parent
446d7cccd4
commit
ccce20cf34
@ -7,10 +7,32 @@ export const useLastImgStore = defineStore('lastImg', {
|
|||||||
actions: {
|
actions: {
|
||||||
setLastImgUrl(lastImgUrl) {
|
setLastImgUrl(lastImgUrl) {
|
||||||
this.imgUrl = 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() {
|
clearCache() {
|
||||||
this.imgUrl = null
|
this.imgUrl = null
|
||||||
|
localStorage.removeItem('lastImgUrl')
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// 可选:添加持久化插件配置
|
||||||
|
persist: {
|
||||||
|
key: 'lastImgUrl',
|
||||||
|
storage: localStorage,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
@ -200,8 +200,10 @@ import { storeToRefs } from 'pinia'
|
|||||||
|
|
||||||
const { t, locale } = useI18n()
|
const { t, locale } = useI18n()
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const lastImgStore = useLastImgStore() //获取图片缓存
|
const lastImgStore = useLastImgStore()
|
||||||
const { imgUrl: lastImgUrl } = storeToRefs(lastImgStore) //国家信息
|
// 初始化时从 localStorage 恢复数据
|
||||||
|
lastImgStore.initFromStorage()
|
||||||
|
const { imgUrl: lastImgUrl } = storeToRefs(lastImgStore) //获取图片缓存
|
||||||
|
|
||||||
// 监听语言变化并设置文档方向
|
// 监听语言变化并设置文档方向
|
||||||
locale.value && setDocumentDirection(locale.value)
|
locale.value && setDocumentDirection(locale.value)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user