Signature
Import
- Component
- Plugin
To ensure optimal bundle sizes,
see Optimize build size.
Vue
About this widget
Use theais-hits
widget to display a list of results.
To set the number of search results,
use the ais-hits-per-page
or ais-configure
widget.
See also:
Examples
Vue
Props
Whether to display a top banner when banner data is included within the
renderingContent
property from the Algolia API response.Vue
Whether to escape HTML entities from hits string values.
Vue
The CSS classes you can override:
ais-Hits
. The widget’s root element.ais-Hits-list
. The list of results.ais-Hits-item
. The list of items.ais-Hits-banner
. The optional banner’s root.ais-Hits-banner-image
. The image element of the optional banner.ais-Hits-banner-link
. The optional anchor element of the optional banner.
Vue
Receives the items and is called before displaying them.
It returns a new array with the same “shape” as the original.
This is helpful when transforming or reordering items.
Don’t use
transformItems
to remove items
since this will affect your pagination.The entire results
data is also available, including all regular response parameters and helper parameters (for example, disjunctiveFacetsRefinements
).If you’re transforming an attribute with the ais-highlight
widget, you must transform item._highlightResult[attribute].value
.To prevent creating infinite loops,
avoid passing arrays, objects, or functions directly in the template.
These values aren’t referentially equal on each render,
which causes the widget to re-register every time.
Instead, define them in your component’s
data
option and reference them in the template.Vue
Customize the UI
default
The slot to override the complete DOM output of the widget.When you implement this slot, none of the other slots will change the output, as the default slot surrounds them.Scope
-
items: object[]
. The records that matched the search. Each element ofitems
has the following read-only properties:__queryID
: the query ID (only ifclickAnalytics
is set totrue
).__position
: the absolute position of the item.
-
banner: object
. The banner data returned within therenderingContent
property from the Algolia API response. -
sendEvent: (eventType, hit, eventName) => void
. The function to sendclick
orconversion
events. Theview
event is automatically sent when this connector renders hits. Learn more about these events in theinsights
middleware documentation.eventType: 'click' | 'conversion'
hit: Hit | Hit[]
eventName: string
-
insights: (method: string, payload: object) => void
: (Deprecated) Sends Insights events.-
method: string
. The Insights method to be called. Only search-related methods are supported:'clickedObjectIDsAfterSearch'
,'convertedObjectIDsAfterSearch'
. -
payload: object
. The payload to be sent.-
eventName: string
: the name of the event. -
objectIDs: string[]
: a list ofobjectID
s. -
index?: string
: the name of the index related to the click. -
queryID?: string
: the AlgoliaqueryID
found in the search response whenclickAnalytics: true
. -
userToken?: string
: a user identifier. -
positions?: number[]
: the position of the click in the list of Algolia search results. When not provided,index
,queryID
, andpositions
are inferred by the InstantSearch context and the passed object IDs:index
by default is the name of the index that returned the passed object IDs.queryID
by default is the ID of the query that returned the passed object IDs.positions
by default is the absolute position of the passed object IDs.
-
-
For more details about the
payload
property, see the Insights client documentation.banner
The slot to override the DOM output of the banner.Scope
banner: object
. The banner data returned within therenderingContent
property from the Algolia API response.
Vue
item
The slot to override the DOM output of the item.Scope
item: object
. A single hit with all its attributes.index: number
. The relative position of the hit in the list.
Vue
HTML output
HTML
Click and conversion events
If theinsights
option is true
,
the ais-hits
widget automatically sends a click
event with the following “shape” to the Insights API whenever users click a hit.
JSON
sendEvent
function in your item
slot and send a custom click
event on the root element.
Vue
sendEvent
function also accepts an object as a fourth argument to send directly to the Insights API.
You can use it, for example, to send special conversion
events with a subtype.
Vue
Use strings to represent monetary values in major currency units (for example, ‘5.45’).
This avoids floating-point rounding issues, especially when performing calculations.