HomeWiki
HomeWiki
  1. Components
  • Back to home
  • 1. Themes
  • Layout
    • New Layout
    • Legacy Layout
  • Components
    • Announcement
    • Banner Carousel
    • Banner With Products Carousel
    • Blog Category List
    • Blog List
    • Brand List
    • Brands Carousel
    • Breadcrumb
    • Call To Action
    • Cart
    • Categories List
    • Change Password
    • Checkout
    • Cookie Manager
    • Filter list
    • Footer
    • Forgot Password
    • Form
    • Hero Carousel
    • Icon Block
    • Invitation
    • Last Visited Products
    • Layout
    • Login
    • Map
    • Nav Bar
    • Offer
    • Product Attachments
    • Product Attributes
    • Product Documentation
    • Product Expected
    • Product Modal
    • Products Block
    • Products Carousel
    • Product Single
    • Profile
    • Quote
    • Register
    • Related Products
    • Search
    • Stores
    • Subscribe Newsletter
    • Text with Image
    • Top Bar
    • Video
  • Reusables
    • Getting Started
  • Assets
    • Getting Started
  • SDK
    • Products
      • _findProductsByCategory
      • _findProductsByIds
      • _findProductsByTitle
      • _findProductsByFilter
      • _findProductsByCriteria
      • _findProductsAndCalculate
      • _findProductsThenCalculate
      • _getProductAttributeSet
      • _setLastVisited
    • Categories
      • _findCategoryTreeById
      • _findCategoriesByIds
      • _findCategoryByAlias
      • _findCategoryTreeByAlias
      • _getCategoryContent
    • Collections
      • _getCollectionContent
      • _findCollectionsByIds
      • _findCollectionsByIdsThenCalculate
    • Brands
      • _getBrandContent
      • _findBrandsByIds
    • Cart
      • _addToCartMulti
      • _addToCart
      • _setCart
      • _clearCart
      • _setCartListener
      • _removeFromCart
      • _calculateCart
    • Checkout
      • _startCheckout
      • _updateCheckout
      • _completeCheckout
    • Shopping Lists
      • _getShoppingLists
      • _updateShoppingList
      • _createShoppingList
      • _deleteShoppingList
      • _getShoppingListByAlias
    • Navigation
      • _getFooterMenu
      • _getHeaderMenu
    • Users
      • _getUserById
    • Utils
      • _calculateCurrency
      • _getCurrencySymbol
      • _getCulture
      • _subscribeToNewsletter
      • _findUnitsByIds
  • Vs Code
    • Getting Started
  1. Components

Categories List

Documentation: Categories List Component#

The Categories List Component is a Vue.js component designed to display a list of categories in a flexible and customizable manner. It can adapt to different data sources and configurations, rendering category items with images and titles.

Overview#

The Categories List Component provides two distinct views:
1.
A navigational view for displaying category items as links with images.
2.
A standard view for showing categories with or without images.
The component leverages Vue.js directives and methods to handle dynamic data and adjust its display based on the provided configuration.

Model Documentation#

The Categories List Component uses a model object to control its behavior and appearance. Here's a breakdown of the properties used in the model:
Model Structure#
The model object should have the following properties:
id: String
A unique identifier for the component. This is used for the component’s id attribute and can be used for styling or targeting the component with JavaScript.
cssClass: String
Optional CSS class(es) for the outer container. This allows for additional styling.
header: String
Optional header text to be displayed at the top of the list. This text is rendered as an <h2> element.
alignment: Number
Controls the alignment of the header text. Possible values are:
1: Left alignment (justify-content-start)
2: Center alignment (justify-content-center)
3: Right alignment (justify-content-end)
categoryIds: Array
An array of category IDs used to fetch category data.
Example Model#
Here is an example of the model object:
{
  "id": "categories-list-1",
  "cssClass": "custom-categories-list",
  "header": "Featured Categories",
  "alignment": 2,
  "categoryIds": ["cat1", "cat2", "cat3"]
}

Component Structure#

The component is implemented using Vue.js features:
1.
HTML Template: Defines the structure and appearance of the categories list.
2.
JavaScript Logic: Manages data retrieval and utility functions.

HTML Template#

The HTML template handles the rendering of categories. It uses Vue.js directives to dynamically generate the list based on the CategoriesList data:

JavaScript#

The JavaScript section manages data initialization, methods, and lifecycle hooks:

Explanation#

1.
Props:
model: The component receives a model object as a prop, containing configuration and data used for rendering.
2.
Data:
fontstyle: Default font style, currently not used.
fontweight: Default font weight, currently not used.
colors: Array for storing colors, currently not used.
title: Default title, currently not used.
navigations: Stores the list of navigational categories.
categories: Stores the list of categories fetched from the backend.
categoryTitle: Title for the current category if available.
3.
Methods:
getImage(category): Returns the URL for the category image, or a default image if none is available.
getAlignmentClass(alignment): Returns a CSS class based on the alignment value for the header.
4.
Mounted Lifecycle Hook:
mounted(): Fetches category data based on the URL and the component's model configuration. Updates categoryTitle, categories, or navigations as needed.

Steps to Create Your Own Categories List Component#

1.
Define the Vue Component:
Use Vue.component() or app.component() to register the component.
2.
Create the Template:
Structure the HTML to include sections for navigations and categories.
Use Vue.js directives (v-if, v-for, :class, etc.) for dynamic rendering.
3.
Implement JavaScript Logic:
Define props for the model object.
Initialize data and implement methods for data retrieval and utility functions.
Use the mounted() lifecycle hook to
Previous
Cart
Next
Change Password
Built with