0👍
✅
Error is because you are modifying Search
prop by using v-model
on your input (SearchBar
component)
Do this instead:
<v-container>
<input class='input'
placeholder="write words for search"
type="text"
v-model="searchPhrase"
/>
</v-container>
</template>
<script>
export default {
name: "SearchBar",
props: {
Search: String
},
computed: {
searchPhrase: {
get() { return this.Search }
set(val) { this.$emit('receivingSelfSearch', val) }
}
}
};
</script>
How using computed property for v-model
works:
- Child receives prop
Search
from the parent (parent owns the data – it hasSearch
indata()
) - When the Child is rendering and needs initial value for the input, it calls getter (
get()
method) which returns value ofSearch
prop - When user changes content of input, Vue will do something like
searchPhrase = new value
, which in turn calls setter - Setter emits the event with new value as an event payload
- Parent listener gets a new value and assign it into the
Search
data variable (@receivingSelfSearch='autoSearch'
) - Vue detects the
Search
is changed and update Child component, updatingSearch
prop inside the Child to a new value
Source:stackexchange.com