mallBackend/src/store/comNav.ts

48 lines
1.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

export const comNavStore = defineStore('main_com_nav', {
state: () => {
return {
topNavList: [] as any, //loading控制,
maxNavCount: 8,
currentNav:''
}
},
getters: {},
actions: {
addNavTarget(ev: any) {
console.log("topNavList", this.topNavList,ev)
this.currentNav = ev.path
if (!this.topNavList.map((ele: any) => ele.path).includes(ev.path)) {
this.topNavList.push(ev)
}
if (this.topNavList.length > this.maxNavCount) {
this.topNavList.splice(0,1)
}
},
deleteNavTarget(index: any) {
if (this.topNavList.length > 0) {
this.topNavList.splice(index, 1)
}
},
clearTarget(val: any) {
this.topNavList = []
},
setCurrentNav(ev:any){
console.log("setCurrentNav")
this.currentNav = ev
}
},
persist: {
enabled: true, // 开启数据缓存
strategies: [
{
// 自定义存储的 key默认是 store.$id
key: 'main_com_nav',
storage: localStorage, //缓存模式 可选 localStorage sessionStorage
// state 中的字段名,按组打包储存
paths: ['topNavList'] //需要缓存的字段 与 state中相关联
}
]
}
})