Suggests terms from an Object using a custom filter to return matches.
<vue-suggest-term
:fields="mappings"
:filter="filter"
:limit="limit"
:list-class="'app-ul'"
:term-selected-class="'selected'"
@selectTerm="updateQuery"
>
<template slot="input">
<textarea
spellcheck="false"
v-model="query"
>
</textarea>
</template>
</vue-suggest-term>
import VueSuggestTerm from './VueSuggestTerm.vue'
export default {
data() {
return {
query: '',
mappings: [
{ name: 'foobar' },
{ name: 'foobell' },
{ name: 'foobull' },
{ name: '$someVal'},
{ name: 'MATCH('},
],
limit: 5,
filter(val, mappings, limit) {
const ret = []
for (let i = 0; i < mappings.length && i < limit; i += 1) {
const entry = mappings[i]
if (entry.name.startsWith(val) ||
entry.name.endsWith(val)) {
ret.push(entry)
}
}
return ret
},
}
},
methods: {
updateQuery(v) {
this.query = v
},
},
components: {
VueSuggestTerm,
}
}
Field Object or Array to match against.
Function to filter field matches
Max number of matching terms to display
Optional CSS class to apply to child ul
Optional CSS class to apply to actively selected term
Event emitted on term selection. Passes the selected term.
yarn serve
- CSS normalization needed for IE for proper positioning