[Vuejs]-Vue js filter don't work when space is pressed

2👍

If you want to match the full name you should check against the first + last with something like:

filterUser(){
   return this.buddylist.filter((buddy)=>{
     var fullname = buddy.oponent.firstName.trim() + " " + buddy.oponent.lastName.trim()
     return fullname.toLowerCase().match(this.search.toLowerCase().trim().replace(/\s+/g,' '))

   })
}

This replaces extra spaces in the user input with one space. Strips any extra space off first and last name. Concatenates the first + last and compares.

If you want to match first name or last name or full name you’ll need to combine this with your previous function.

👤Mark

Leave a comment