¶Ô±ÈÐÂÎļþ |
| | |
| | | import { ref, watch } from 'vue' |
| | | |
| | | const StateKey = Symbol('state').toString() |
| | | |
| | | // sessionStorage.setItem('state', ) |
| | | const stateStr = localStorage.getItem(StateKey) || '{}' |
| | | |
| | | let initValue = {} |
| | | try { |
| | | initValue = JSON.parse(stateStr) |
| | | } catch (error) { |
| | | console.error(error) |
| | | } |
| | | // console.log(initValue, 'initValue') |
| | | /** |
| | | * æ¬å°å¼å模æå³ä¾§æ ·å¼åè½Barï¼ç¦æ¢æ·»å 任使°æ® |
| | | */ |
| | | export const state = ref<Record<string, any>>(initValue) |
| | | |
| | | watch( |
| | | state, |
| | | (v) => { |
| | | if (Object.keys(state.value).length) { |
| | | localStorage.setItem(StateKey, JSON.stringify(v)) |
| | | } |
| | | }, |
| | | { |
| | | deep: true, |
| | | } |
| | | ) |