I
I
Ilya Fedorov2017-04-21 11:55:35
JavaScript
Ilya Fedorov, 2017-04-21 11:55:35

How to make a filter on Vue.js on click?

There is a live filter using Vue2Filters. The value from v-model is substituted into the filterBy() function.
Is it possible somehow to apply the filter only when the "FILTER" button is clicked?

input(type="text",class='filter_tags form-control',v-model="input",autofocus='')
button.searchBtn(type="button") ФИЛЬТР
br
table(:id="getTableClass")#table-tagsdata.table.table-tags.table-bordered
    tr
       th(v-for='tth in tagshead') {{tth}}
    template(v-for='tagObj in filterBy(tagsdata, input)')

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Evgeny Kulakov, 2017-04-21
@kulakoff Vue.js

You can add another variable to the component's data and assign it a value from the input in the button handler:
Here

template(v-for='tagObj in filterBy(tagsdata, input)'
change to
template(v-for='tagObj in filterBy(tagsdata, some_value)'

I
Ilya Fedorov, 2017-04-21
@dedmoroz007

Okay, thanks Evgeny Kulakov ! To get a working filter on click, I did this:
in the template, I left the input
in the search field in the v-model directive put the property of the data object - search_value
I also added the input property to data and it turned out:

data: function() {
      return {
        search_value: '',
        input: ''
      };
    }

In the "FILTER" button, by clicking on the input property, by which the values ​​are filtered, I assign the search_value value from the search string:
input.searchBtn(type="button", v-on:click="input=search_value", value="ФИЛЬТР")

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question