@troj something like this codepen here?
Jan 3, 2020
10
Level 4
Close on click outside element in Vue
Hi,
I've made this autocomplete functionality (with the help of youtube). Everything is working great. But one thing i cant figure out. And i know it has to do something with eventlisteners. But how to implement that in this code, i aint got no clue. Hope someone can help me with that.
I would like the dropdown to disappear when someone clicks outside it.
methods:{
autoComplete (){
this.results=[];
//alert(this.searchText);
if(this.searchText !== '') {
axios.post(this.bUrl + '/search', {
searchText:this.searchText
})
.then((response) =>{
console.log(response);
app.results = response.data;
})
}
}
}
Level 73
@troj I cannot see your full component. I don't know what flag you use to decide if the dropdown is opened or not.
You can add a blur event to your component, and trigger an action/method on blur, exactly like the codepen does..
So on the component @blur="onBlur" and in the methods add :
onBlur: function () {
this.dropdownOpen = false; // or whatever flag you use here for the dropdown component.
},
Please or to participate in this conversation.