[Vuejs]-Search vue.js with laravel api

0πŸ‘

It should be

filterSearch(){
    return this.teachers.data.filter((teacher) => {
        return this.employees = teacher.name.match(this.searchTerm);
    })
}

teachers.data.filter vs. teachers.filter as you have it β€” since you are holding an object inside the teachers, not an array. Which I’d suggest the opposite – make the teachers the array and in the getTeachers() method do this.teachers = response.data.data

Then also make the employees property an array too. B/c after filtering teachers array within the computed property, you will get an array back, not the object.

If you follow this route – make both teachers and employees an array – then your computed property should not change and it will work as you have it

Leave a comment