L
L
lookingfor22020-10-01 14:41:11
Vue.js
lookingfor2, 2020-10-01 14:41:11

How to make a search component on Vue?

At the moment I have a search method in the component

В templatesList у меня хранится список пользователей
data() {
    return {
      templatesList: this.$store.getters.templatesList,
    };
  },
//метод поиска
search(searchValue) {
      if (searchValue.length > 0) {
        this.templatesList = this.templatesList.filter(item => item.name.indexOf(this.searchValue) !== -1);
      } else {
        this.templatesList = this.$store.getters.templatesList;
      }
      return this.templatesList;
    },


But the search will be used in another component, in data there will be another array with data. How to make search a universal component?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Yarkov, 2020-10-01
@lookingfor2

Pass an array as a prop

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question