Skip to content

Commit 331d92a

Browse files
committed
Init to store value & react if it changes
1 parent 6eafdf4 commit 331d92a

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/components/FilterPanel/CtlSwitch.vue

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@ const { controlSet } = defineProps({
1919
})
2020
2121
const appStore = useAppStore()
22-
const controlValue = ref(false)
22+
23+
const getStoreValue = () => {
24+
const parentKey = appStore.currentPageName
25+
return appStore[parentKey]?.[controlSet.storeKey]
26+
}
27+
28+
const controlValue = ref(getStoreValue() ?? controlSet.defaultValue ?? false)
2329
2430
const resetInput = inject('resetInput')
2531
@@ -28,6 +34,12 @@ watch(resetInput, () => {
2834
appStore.updateSwitch(controlSet.storeKey, controlSet.defaultValue)
2935
})
3036
37+
watch(getStoreValue, (newValue) => {
38+
if (newValue !== undefined && newValue !== controlValue.value) {
39+
controlValue.value = newValue
40+
}
41+
})
42+
3143
onMounted(() => {
3244
populateControlData()
3345
})

0 commit comments

Comments
 (0)