mirror of
https://github.com/KevinMidboe/seasoned.git
synced 2026-03-11 11:55:38 +00:00
On every route change, update local variables from query params
This commit is contained in:
@@ -18,7 +18,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, computed } from "vue";
|
import { ref, computed, watch } from "vue";
|
||||||
import { useRoute, useRouter } from "vue-router";
|
import { useRoute, useRouter } from "vue-router";
|
||||||
|
|
||||||
import ResultsSection from "@/components/ResultsSection.vue";
|
import ResultsSection from "@/components/ResultsSection.vue";
|
||||||
@@ -45,6 +45,7 @@
|
|||||||
|
|
||||||
const title = computed(() => `Search results: ${query.value}`);
|
const title = computed(() => `Search results: ${query.value}`);
|
||||||
|
|
||||||
|
function readQueryParams() {
|
||||||
const urlQuery = route.query;
|
const urlQuery = route.query;
|
||||||
if (urlQuery && urlQuery?.query) {
|
if (urlQuery && urlQuery?.query) {
|
||||||
query.value = decodeURIComponent(urlQuery?.query?.toString());
|
query.value = decodeURIComponent(urlQuery?.query?.toString());
|
||||||
@@ -52,6 +53,7 @@
|
|||||||
adult.value = Boolean(urlQuery?.adult) || adult.value;
|
adult.value = Boolean(urlQuery?.adult) || adult.value;
|
||||||
mediaType.value = (urlQuery?.media_type as MediaTypes) || mediaType.value;
|
mediaType.value = (urlQuery?.media_type as MediaTypes) || mediaType.value;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const search = (
|
const search = (
|
||||||
_page = page.value || 1,
|
_page = page.value || 1,
|
||||||
@@ -73,6 +75,12 @@
|
|||||||
function toggleChanged() {
|
function toggleChanged() {
|
||||||
updateQueryParams();
|
updateQueryParams();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
readQueryParams();
|
||||||
|
watch(
|
||||||
|
() => route.fullPath,
|
||||||
|
() => readQueryParams()
|
||||||
|
);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
|
|||||||
Reference in New Issue
Block a user