You are trying to create your own widget with Vue InstantSearch and that’s awesome but that also means that you couldn’t find the widgets or built-in options you were looking for. Algolia would love to hear about your use case as the aim of the InstantSearch libraries is to provide the best out-of-the-box experience. Don’t hesitate to send a quick message explaining what you were trying to achieve either using the form at the end of that page or directly by submitting a feature request.
Existing connectors
Sometimes you might want to create a component which uses a piece of data not provided by any of the widgets. You also might want to make a custom component for having access to the data in different places than the template. You can do this with thecreateWidgetMixin
function exposed by Vue InstantSearch.
It works together with the connectors from InstantSearch.js. To get started, choose the connectMenu
connector for this example.
created
). All information will be available on this.state
on your instance, and will be null
initially (so make sure your code is safe by wrapping usage in the template for example in an v-if="state"
).
All connectors expect to be passed widget parameters.
Since these change over the lifecycle of a component, and are usually passed through props, the widget mixin expects a property widgetParams
on the component’s instance.
Create it with a computed
property, based on props:
Vue
state
here to for example filter over the items (note that this is also possible with transform-items
prop on ais-menu
):
Vue
Vue
Custom connectors
Finally, if you want to make your own connector, you can do that using a function with this signature:JavaScript