[Vuejs]-How to include .filter function in my data filtering component

0👍

methods: {
    onChange() {
      axios
        .get("myURL")
        .then((response) => {
        this.filteredresults=FilterOnInput((response.data,document.getelementById("IdOfTheInput").value)

        })
        .catch((error) => {
          console.log(error);
          this.errors = true;
        })
        .finally(() => console.log("Data successfully loaded"));
      this.modal = true;
    },
    
//new !!
  FilterOnInput(list, inputFilter) {
  let filteredList = [];
  for (let i = 0; i < list.length; i++) {
    let name = list[i].Name; //if given returns are objects 
    if (name.toUpperCase().includes(inputFilter.toUpperCase())) {
      filteredList.push(list[i]);
    }
  }
  if (inputFilter.length === 0) {
    filteredList = list;
  }
  return filteredList;
}

This getelementById("IdOfTheInput").value is only needed when working with id if you use a v-model, just put the name of the variable you use.

Leave a comment