Seb-L / pinia-plugin-persist

Persist pinia state data in sessionStorage or other storages.
https://Seb-L.github.io/pinia-plugin-persist/
MIT License
214 stars 37 forks source link

Proposal to Add Cross-Page State Synchronization to Pinia Plugin Persist #62

Open yansenlei opened 1 year ago

yansenlei commented 1 year ago

It is suggested to add a new feature to enable cross-page state synchronization in Pinia Plugin Persist. This feature can work with listening to the localStorage event, which will automatically synchronize the status of other web pages after one page updates the status. This will make it easier to handle most complex synchronization logic.

useEventListener(window, 'storage', (event) => {
    if (event.key === STORAGE_KEY) {
      const obj = JSON.parse(event.newValue || '{}')
      mykey.value = obj.mykey
    }
})