shareStore状态优化

This commit is contained in:
zhangxuelin 2024-08-16 17:33:27 +08:00
parent 631fcf38f7
commit 56483a9a49
1 changed files with 6 additions and 4 deletions

View File

@ -13,12 +13,14 @@ export function shareStorePlugin({store}) {
// 在存储变化的时候执行
// const storeName = store.$id
// const storeName = mutation.storeId
const { storeId: storeName, payload, events, type } = mutation // direct
// if (!Object.keys(payload).length) return
if (type != 'direct') return
// 用于多窗口共享(需要共享的状态名称)
const names = ['tool']
if (names.includes(storeName)) stateSync(storeName, events.key, events.newValue) // 需要同步
if (names.includes(storeName)) {
const { storeId: storeName, payload, events, type } = mutation // direct
// if (!Object.keys(payload).length) return
if (type != 'direct' || !events || Array.isArray(events) || !events.key) return
stateSync(storeName, events.key, events.newValue) // 需要同步
}
})
// 暴露方法-手动同步
store.stateSync = (storeName, key, value) => {