Composables
Interfaces
UseRecentlyViewedProductsOptions
This composable can be used to track a short history of products a customer has previously viewed using local storage. It maintains up to 10 recently viewed products and provides methods to add new products and fetch their full details.
Param
An object containing parameters and options for the loading the products.
Param
The fields to include in the response.
Param
The price promotion key.
Properties
| Property | Type |
|---|---|
pricePromotionKey? | string |
with? | ProductWith |
UseRecentlyViewedProductsReturn
Properties
| Property | Type | Description |
|---|---|---|
addProductId | (productId: number) => void | Adds a product id to the list of recently viewed products and persists it to local storage. Because this function uses local storage, it is not available on the server. Throws Error if the function is called on the server. |
error | Ref< | Error | undefined> | A reactive container for any errors that occur during fetching. |
loading | Ref<boolean> | A reactive flag indicating if the product data is being fetched. |
loadMissingProducts | () => Promise<void> | Loads products based on the product ids previously added. Initially all products within the persisted list are loaded. Subsequent calls only load products that are not already loaded. Because this function uses local storage, it is not available on the server. Throws Error if the function is called on the server. |
products | Ref<Product[]> | A reactive array of the fetched, full Product objects. |
status | Ref<AsyncDataRequestStatus> | A string indicating the status of the data request |
Functions
useRecentlyViewedProducts()
Parameters
| Parameter | Type |
|---|---|
options? | UseRecentlyViewedProductsOptions |
Returns