Is there a way to pass the current component's reference to a child component in Vue.js?
<template>
<div class="screen" ref="screen">
<child-component :screenRef="screenRef">
</child-component>
</div>
</template>
<script>
const Parent = {
name: 'parent',
data: {
screenRef: {}
},
mounted() {
this.screenRef = this.$refs['screen']
}
}
</script>
I'm encountering an issue when trying to define screenRef
as a prop in the child component, as Vue.js types do not support HTMLDivElement
.
const ChildComponent = {
name: 'child',
props: {
screen: {
type: HTMLDivElement,
default: {}
}
}
}
If you have any suggestions or solutions on how to correctly achieve this, please share!