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
hi @Yatharth 👋 , can you show how you tried adding the "favorite" method?
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
@Yatharth , this should help you https://docs.vuestorefront.io/v2/composition/composables.html
Composables | Vue Storefront 2
Vue Storefront 2 documentation
I was actually reading this but this does not clear up my questions.
Do you have any other resource that can help?
@rohrig
@Yatharth have you seen this?: https://docs.vuestorefront.io/v2/composition/creating-custom-composables.html
Creating custom composables | Vue Storefront 2
Vue Storefront 2 documentation
Thanks I will check