I built a basic search function to get real-time search results from backend. The flow is basically like this
1 - watch search input, if length > 2 then send the changes a query to backend and fetch the results in the table.
watch:{
search(val,old){
if (val.length >= 2 || old.length >= 2){
this.setList({url:`/customer/my-bag/global-filter`, query_value:val}).then((res) =>{
this.pagination.lastPage = res.data.meta.last_page
})
2 - If the search input is ''
then get all customers paginate them in 5 pages.
if (this.search === ''){
this.loadCustomers()
}
SetList
is a method in the store to get the result from API
methods: {
...mapActions("users", ["setList"]),
Result
Too many API requests for one search query ( around 40 requests). My goal is to make the search way better in terms of requests and "correct" method.