-
Notifications
You must be signed in to change notification settings - Fork 13
/
.code-samples-vue-3.meilisearch.yaml
106 lines (91 loc) · 3.37 KB
/
.code-samples-vue-3.meilisearch.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
landing_getting_started: |-
// In main.js
import { createApp } from 'vue';
import App from './App.vue';
import InstantSearch from 'vue-instantsearch/vue3/es';
import "instantsearch.css/themes/algolia-min.css";
import "@meilisearch/instant-meilisearch/templates/basic_search.css";
createApp(App).use(InstantSearch).mount('#app');
// In App.vue
<template>
<ais-instant-search
:search-client="searchClient"
index-name="steam-video-games"
>
<ais-search-box />
<ais-hits>
<template v-slot:item="{ item }">
<ais-highlight :hit="item" attribute="name" />
</template>
</ais-hits>
</ais-instant-search>
</template>
<script>
import { instantMeiliSearch } from "@meilisearch/instant-meilisearch";
export default {
data() {
return {
searchClient: instantMeiliSearch(
"https://ms-adf78ae33284-106.lon.meilisearch.io",
"a63da4928426f12639e19d62886f621130f3fa9ff3c7534c5d179f0f51c4f303",
).searchClient,
};
},
};
</script>
getting_started_front_end_integration_md: |-
The following example uses [Vue 3](https://vuejs.org/), a JavaScript framework for building web user interfaces.
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@meilisearch/instant-meilisearch/templates/basic_search.css" />
</head>
<body>
<div id="app" class="wrapper">
<ais-instant-search :search-client="searchClient" index-name="steam-video-games">
<ais-search-box></ais-search-box>
<ais-hits>
<template v-slot:item="{ item }">
<ais-highlight :hit="item" attribute="name" />
</template>
</ais-hits>
</ais-instant-search>
</div>
</body>
<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/vue3/umd/index.js"></script>
<script
src="https://cdn.jsdelivr.net/npm/@meilisearch/instant-meilisearch/dist/instant-meilisearch.umd.min.js">
</script>
<script type="module">
const InstantSearch = {
install(localVue) {
Object.keys(VueInstantSearch).forEach(widgetName => {
localVue.component(VueInstantSearch[widgetName].name, VueInstantSearch[widgetName]);
});
},
};
const app = Vue
.createApp({
data() {
return {
searchClient: instantMeiliSearch(
'https://ms-adf78ae33284-106.lon.meilisearch.io',
'a63da4928426f12639e19d62886f621130f3fa9ff3c7534c5d179f0f51c4f303',
).searchClient,
}
}
})
.use(InstantSearch)
.mount('#app')
</script>
</html>
```
Here's what's happening:
- To use `instant-meilisearch` with Vue, you must add `<ais-instant-search>`, `<ais-search-box>`, and `<ais-hits>` to your application's HTML. These components are mandatory when generating the `instant-meilisearch` interface
- Other Vue components such as `<ais-configure>` and `<ais-highlight>` are optional. They offer greater control over `instant-meilisearch`'s behavior and appearance
- The three `<script src="..">` tags import libraries needed to run `instant-meilisearch` with Vue
- The fourth and final `<script>` creates a new Vue instance and instructs it to use `instant-meilisearch`