darrenjennings / vue-autosuggest

🔍 Vue autosuggest component.
https://darrenjennings.github.io/vue-autosuggest
MIT License
621 stars 91 forks source link

[Question] @select argument #199

Closed aeon3k closed 4 years ago

aeon3k commented 4 years ago

Hi, First I wanted to thank you for this great component.

I'm using the latest version of this component 2.2.

I have a question for a specific usecase of mine. I want to be able when I call @selected, to pass an additional argument

<vue-autosuggest
                                    ref="autocomplete"
                                    v-model="autocompleteText[ind]"
                                    :suggestions="suggestions"
                                    :inputProps="inputProps"
                                    :renderSuggestion="renderSuggestion"
                                    :getSuggestionValue="getSuggestionValue"
                                    @input="fetchResults"
                                    @selected="selectSuggestion(ind)"
                                  />

@selected already use 2 arguments as you know :

    selectSuggestion(suggestionItem, suggestionIndex  ){
        ...
    },

Obviously I can display the first 2 arguments succesfully but how can I display my additional argument ? Thanks for your help and sorry the noob question ;)

darrenjennings commented 4 years ago

Thanks for the kind words 🤗 You can accomplish this by wrapping it in an in-line function:

  @selected="(...args) => selectSuggestion(...args, ind)"

Or

  @selected="(suggestionItem, suggestionIndex) => selectSuggestion(suggestionItem, suggestionIndex, ind)"
aeon3k commented 4 years ago

thanks a lot !