[Vuejs]-Issue in throttling ajax requests using vue-multiselect and lodash

0πŸ‘

βœ…

@strelok2010 is nearly right but I think he overlooked the fact that the vue multiselect @search-change handler expects a handler that takes the search argument and so the code won’t work as is. Also I think, this won’t resolve to the component inside the arrow function and so you may have to use standard JS function. Here is what I think would work.

findLocations: throttle(function(search) {
      this.$log.debug("Going to find locations for search criteria", search)
      const params = {search: search}
      const self = this
      this.locationsLoading = true
      self.$http.get("locations/ddlist", {params}).then(res => {
        self.allLocations = res.data.items
        self.locationsLoading = false
      }
}, 5000)

0πŸ‘

Try to wrap findLocations method to throttle function:

findLocations: throttle(() => {
      this.$log.debug("Going to find locations for search criteria", search)
      const params = {search: search}
      const self = this
      this.locationsLoading = true
      self.$http.get("locations/ddlist", {params}).then(res => {
        self.allLocations = res.data.items
        self.locationsLoading = false
      }
}, 5000)

More info here

Leave a comment