I am trying to only show an overlay, if my search input contains any text.
This is my template, where my input field is:
Input.vue
:
<template>
<div>
<input v-model="query" class="input" placeholder="Global search..."></input>
</div>
</template>
<script>
export default {
data() {
return {
query: '',
};
}
};
</script>
When I check in my console, query
updates to whatever text I write in my input field.
I then try to pass this variable to another component, which holds my overlay div:
Overlay.vue
:
<template>
<div v-if="this.$root.query.length > 0">
<div class="search-overlay is-active"></div>
</div>
</template>
However, this gives me below error:
[Vue warn]: Error in render: "TypeError: Cannot read property 'length' of undefined"
What am I doing wrong here?
this.$root
? Could you provide more details about your different components ? – Thomas Lombartquery
object as a prop to your overlay component :<overlay :query="query" />
and define the prop inside yourOverlay.vue
. – Thoomas