1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
| 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,
| }
| )
|
|