Newer
Older
<div class="autocomplete-container" :class="$vuetify.breakpoint.name">
v-model="select"
:loading="loading"
:items="items"
:search-input.sync="search"
item-text="label"
:menu-props="{maxHeight: $vuetify.breakpoint.name === 'xs' ? 190 : 500, transition: 'fade-transition', allowOverflow: true}"
:append-icon="null"
full-width
<span class="search-hit">{{data.item.label}} </span> ({{data.item.lang ? data.item.lang : 'fritekstsøk'}})
import debounce from "debounce"
},
data: function() {
return {
loading: false,
items: [],
search: null,
debounced: debounce(function(q, self) {
self.loading = true
return axios.get(self.endpoint + 'suggest?', { params: {q: encodeURIComponent(q),
dict: this.$parent.lang,
n: 9}} )
.then(
function(response) {
response.data.forEach((item, i) => {
hit.lang = item[1][1] ? "bm, nn" : {"bob": "bm", "nob": "nn"}[item[1][0]]
hits.push(hit)
self.items = hits
let currentSearch = self.$refs.autocomplete.searchInput
self.items.push({q: currentSearch, label: currentSearch + ' '})
}
},
watch: {
search (val) {
if (! val) {
this.items = []
} else {
this.run_query(val)
}
this.items = []
this.suggesting = false
this.$emit('submit', item)
let self = this
setTimeout(() => self.$refs.autocomplete.$refs.input.select(), 1)
}
}
},
methods: {
run_query(q) {
<style scoped>
.search-hit {
font-weight: bold;
margin-right: 5px;
color: var(--v-primary-base);
padding-left: 10px;
padding-right: 10px;