Fix pagination problem
This commit is contained in:
@@ -24,7 +24,7 @@ const currentCategory = computed({
|
|||||||
router.push({
|
router.push({
|
||||||
name: "products-slug",
|
name: "products-slug",
|
||||||
params: { slug: ["category", newValue] },
|
params: { slug: ["category", newValue] },
|
||||||
query: { ...route.query },
|
query: { ...route.query, page: "1" },
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ const useGetProducts = () => {
|
|||||||
sort,
|
sort,
|
||||||
in_stock,
|
in_stock,
|
||||||
has_discount,
|
has_discount,
|
||||||
slug,
|
|
||||||
price_gte,
|
price_gte,
|
||||||
price_lte,
|
price_lte,
|
||||||
};
|
};
|
||||||
@@ -45,24 +44,11 @@ const useGetProducts = () => {
|
|||||||
watch(
|
watch(
|
||||||
() => filters_clone.value,
|
() => filters_clone.value,
|
||||||
() => {
|
() => {
|
||||||
queryClient.cancelQueries({
|
|
||||||
queryKey: [
|
|
||||||
QUERY_KEYS.products,
|
|
||||||
searchDebounced,
|
|
||||||
sort,
|
|
||||||
in_stock,
|
|
||||||
has_discount,
|
|
||||||
products_category,
|
|
||||||
price_gte,
|
|
||||||
price_lte,
|
|
||||||
page,
|
|
||||||
],
|
|
||||||
});
|
|
||||||
page.value = 1;
|
page.value = 1;
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
deep: true,
|
deep: true,
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
// methods
|
// methods
|
||||||
|
|||||||
@@ -15,13 +15,12 @@ export const useAppParams = () => {
|
|||||||
mode: "replace",
|
mode: "replace",
|
||||||
});
|
});
|
||||||
|
|
||||||
const page = useRouteQuery<number | undefined>("page", 1, {
|
const page = useRouteQuery("page", "1", {
|
||||||
mode: "push",
|
mode: "push",
|
||||||
transform: (value) => (!!value ? +value : undefined),
|
transform: {
|
||||||
});
|
get: (v) => Number(v),
|
||||||
|
set: (v: number) => String(v),
|
||||||
const category = useRouteQuery<string | undefined>("category", "", {
|
},
|
||||||
mode: "replace",
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const status = useRouteQuery<string | undefined>("status", undefined, {
|
const status = useRouteQuery<string | undefined>("status", undefined, {
|
||||||
@@ -68,7 +67,6 @@ export const useAppParams = () => {
|
|||||||
sort,
|
sort,
|
||||||
search,
|
search,
|
||||||
page,
|
page,
|
||||||
category,
|
|
||||||
price_gte,
|
price_gte,
|
||||||
price_lte,
|
price_lte,
|
||||||
in_stock,
|
in_stock,
|
||||||
|
|||||||
@@ -1,4 +1,10 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
|
||||||
|
// import
|
||||||
|
|
||||||
|
import { useAppParams } from "~/composables/global/useAppParams";
|
||||||
|
import useGetProducts from "~/composables/api/products/useGetProducts";
|
||||||
|
|
||||||
// meta
|
// meta
|
||||||
|
|
||||||
definePageMeta({
|
definePageMeta({
|
||||||
@@ -11,11 +17,6 @@ definePageMeta({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// import
|
|
||||||
|
|
||||||
import { useAppParams } from "~/composables/global/useAppParams";
|
|
||||||
import useGetProducts from "~/composables/api/products/useGetProducts";
|
|
||||||
|
|
||||||
// state
|
// state
|
||||||
|
|
||||||
const { search } = useAppParams();
|
const { search } = useAppParams();
|
||||||
|
|||||||
Reference in New Issue
Block a user