Answer the question
In order to leave comments, you need to log in
vue components?
there is a search component:
Vue.component('search', {
data () {
return {
userSearch: ''
}
},
template:
`
<form action="#" class="search-form" @submit.prevent='this.$refs.filter(userSearch)'>
<input type="text" class="search-field" v-model='userSearch'>
<button type="submit" class="btn-search">
<i class="fas fa-search"></i>
</button>
</form>
`
<search ref="userSearch"></search>
filter(userSearch){
let regexp = new RegExp(userSearch, 'i');
this.filtered = this.products.filter(el => regexp.test(el.product_name));
}
<form action="#" class="search-form" @submit.prevent='this.$refs.filter(userSearch)'>
not this.$refs.filter(userSearch)
$emit('search', userSearch)
(when using such a notation, the method will look like thisfilter(){
let regexp = new RegExp(this.userSearch, 'i');
this.filtered = this.products.filter(el => regexp.test(el.product_name));
}
),
then everything seems to work, but the userSearch value in the new Vue object is not updated with the content in the input
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question