3👍
✅
The vue-typeahead-component
available events only include hit
and input
events, so you can’t apply @blur
to the component itself.
To add an event listener on the inner <input>
of vue-bootstrap-typeahead
:
- Use a template ref on the
<vue-bootstrap-typeahead>
component. - From the ref, get its root DOM element via
vm.$el
. - Use
Element.querySelector()
to get the inner<input>
. - Use
EventTarget.addEventListener('blur', handler)
to listen to theblur
event on the<input>
.
<template>
<vue-bootstrap-typeahead ref="typeahead" 1️⃣ />
</template>
<script>
export default {
async mounted() {
await this.$nextTick()
this.$refs.typeahead.$el 2️⃣
.querySelector('input') 3️⃣
.addEventListener('blur', (e) => console.log('blur', e)) 4️⃣
},
}
</script>
Source:stackexchange.com