< ais-query-rule-custom-data
// Optional parameters
: transform-items = " function "
/>
Import
To ensure optimal bundle sizes,
see Optimize build size . import { AisQueryRuleCustomData } from "vue-instantsearch" ;
// Use "vue-instantsearch/vue3/es" for Vue 3
export default {
components: {
AisQueryRuleCustomData
} ,
// ...
} ;
This imports all widgets, even the ones you don’t use.
For more information, see Get started with Vue InstantSearch . import Vue from "vue" ;
import InstantSearch from "vue-instantsearch" ;
// Use "vue-instantsearch/vue3/es" for Vue 3
Vue . use ( InstantSearch );
See this widget in action Preview this widget and its behavior.
The ais-query-rule-custom-data widget displays custom data from Rules .
You can use this widget to display banners or recommendations returned by rules when they match search parameters.
Examples
< ais-query-rule-custom-data >
< template v-slot:item = "{ item }" >
< h2 > {{ item.title }} </ h2 >
< a :href = "item.link" >
< img :src = "item.banner" :alt = "item.title" />
</ a >
</ template >
</ ais-query-rule-custom-data >
Props
< template >
< ais-query-rule-custom-data : transform-items = " transformItems " />
</ template >
< script >
export default {
methods: {
transformItems ( items ) {
return items . filter (( item ) => Boolean ( item . banner ));
},
/* or, combined with results */
transformItems ( items , { results }) {
return items . map (( item ) => ({
... item ,
visible: results . page === 0 ,
}));
},
} ,
} ;
</ script >
Customize the UI
The slot to override the complete DOM output of the widget. The following example assumes a rule returned this custom data. {
"title" : "This is an image" ,
"banner" : "image.png" ,
"link" : "https://website.com/"
}
When you implement this slot,
none of the other slots will change the output,
as the default slot surrounds them. Scope
items: object[]. The items returned by the rules.
< ais-query-rule-custom-data >
<template v-slot="{ items }">
<ol>
<li v-for="item in items" :key="item.title">
<h2>{{ item.title }}</h2>
<a :href="item.link">
<img
:src="item.banner"
:alt="item.title"
/>
</a>
</li>
</ol>
</template>
</ ais-query-rule-custom-data >
The slot to override the DOM output of the item returned by the rules. The following example assumes a Query Rule returned this custom data. {
"title" : "This is an image" ,
"banner" : "image.png" ,
"link" : "https://website.com/"
}
Scope
item: object. The item returned by the Rules.
< ais-query-rule-custom-data >
<template v-slot:item="{ item }">
<h2>{{ item.title }}</h2>
<a :href="item.link">
<img
:src="item.banner"
:alt="item.title"
/>
</a>
</template>
</ ais-query-rule-custom-data >
HTML output
< div class = "ais-QueryRuleCustomData" ></ div >
Last modified on March 23, 2026