I have an input like below.
<input
type="text"
maxlength="50"
v-on:input="query = $event.target.value"
v-on:keyup.enter="once(search)"
/>
And there is a method called search and once of lodash.
import _ from 'lodash'
methods:{
once(func){
return _.once(func)
},
async search(){
// An api call is in it
}
}
But in this case, it says "search is undefined".
How can I make this case well?
Error is given while your trying to pass a method to your function while it expects a data element.
Instead of using once of lodash, you better could use the eventhandler of vue itself once https://v2.vuejs.org/v2/guide/events.html#Event-Modifiers.
Use:
v-on:keyup.enter.once