A
Alokai•2y ago
Yatharth

How to add custom function to a composable

import { Context, useFacetFactory, FacetSearchResult } from '@vue-storefront/core'; import type { UseFacetSearchParams as SearchParams } from '../types'; const factoryParams = { // eslint-disable-next-line @typescript-eslint/no-unused-vars search: async (context: Context, params: FacetSearchResult<SearchParams>) => { console.log('Mocked: useFacet.search'); const data = await context.$bagisto.api.getProduct(params?.input?.page); return data; } }; export const useFacet = useFacetFactory<SearchParams>(factoryParams); This is my useFacet composable what changes need to be done if I want to add a favorite method to it If I am adding a favorite method here I am unable to use it in my pages directly it says favorite is not a function
6 Replies
rohrig
rohrig•2y ago
hi @Yatharth 👋 , can you show how you tried adding the "favorite" method?
Yatharth
YatharthOP•2y ago
import { Context, useFacetFactory, FacetSearchResult } from '@vue-storefront/core'; import type { UseFacetSearchParams as SearchParams } from '../types'; const factoryParams = { // eslint-disable-next-line @typescript-eslint/no-unused-vars search: async (context: Context, params: FacetSearchResult<SearchParams>) => { console.log('Mocked: useFacet.search'); const data = await context.$bagisto.api.getProduct(params?.input?.page); return data; }, favorite: async (context: Context, params: any) => { console.log('Mocked: useFacet.Favorite'); }, }; export const useFacet = useFacetFactory<SearchParams>(factoryParams); something like this do I need to add favorite to some type file I am new so I don't understand what is happening here @rohrig
rohrig
rohrig•2y ago
Composables | Vue Storefront 2
Vue Storefront 2 documentation
Yatharth
YatharthOP•2y ago
I was actually reading this but this does not clear up my questions. Do you have any other resource that can help? @rohrig
Yatharth
YatharthOP•2y ago
Thanks I will check
Want results from more Discord servers?
Add your server