generated from Seekra/repository-template
feat(settings): get current section using watchEffect
This commit is contained in:
@@ -29,19 +29,27 @@ const router = useRouter();
|
|||||||
const settingsLoaded = ref(false)
|
const settingsLoaded = ref(false)
|
||||||
const settings = ref([]);
|
const settings = ref([]);
|
||||||
const activeSectionContent = ref([]);
|
const activeSectionContent = ref([]);
|
||||||
|
const activeSection = ref(null);
|
||||||
|
|
||||||
|
watchEffect(() => {
|
||||||
|
const segments = route.path
|
||||||
|
.split('/')
|
||||||
|
.filter(Boolean);
|
||||||
|
|
||||||
|
activeSection.value = segments[1];
|
||||||
|
});
|
||||||
|
|
||||||
const updateSettings = function updateSettings () {
|
const updateSettings = function updateSettings () {
|
||||||
const activeSection = getActiveSection();
|
if (activeSection.value) {
|
||||||
if (activeSection) {
|
activeSectionContent.value = settings.value.filter((section) => section.name === activeSection.value)[0];
|
||||||
activeSectionContent.value = settings.value.filter((section) => section.name === activeSection)[0].content;
|
|
||||||
} else {
|
} else {
|
||||||
activeSectionContent.value = [];
|
activeSectionContent.value = { content: [] };
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
settings.value = (await loadSettingsConfig()).contents;
|
settings.value = (await loadSettingsConfig()).contents;
|
||||||
if (!settings.value.map((section) => section.name).includes(getActiveSection())) {
|
if (!settings.value.map((section) => section.name).includes(activeSection.value)) {
|
||||||
router.push('/settings');
|
router.push('/settings');
|
||||||
};
|
};
|
||||||
watchEffect(() => {
|
watchEffect(() => {
|
||||||
@@ -49,14 +57,6 @@ onMounted(async () => {
|
|||||||
});
|
});
|
||||||
settingsLoaded.value = true;
|
settingsLoaded.value = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
const getActiveSection = function getActiveSection () {
|
|
||||||
const segments = route.path
|
|
||||||
.split('/')
|
|
||||||
.filter(Boolean);
|
|
||||||
|
|
||||||
return segments[1];
|
|
||||||
};
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -73,7 +73,7 @@ const getActiveSection = function getActiveSection () {
|
|||||||
<RouterLink
|
<RouterLink
|
||||||
:to="`/settings/${section.name}`"
|
:to="`/settings/${section.name}`"
|
||||||
class="button button-link link sidebar-section"
|
class="button button-link link sidebar-section"
|
||||||
:class="{ active: getActiveSection() === section.name }"
|
:class="{ active: activeSection === section.name }"
|
||||||
>
|
>
|
||||||
{{ t(section.i18n) }}
|
{{ t(section.i18n) }}
|
||||||
</RouterLink>
|
</RouterLink>
|
||||||
|
|||||||
Reference in New Issue
Block a user