I've been googling for hours, reading countless vue docs and relevant posts on stackoverflow without luck.
I need to access an internal property of a component, because that component is nothing but a wrapper for a vanilla component which I need access to in the parent.
I am trying to create a ref which is unique and accessible only inside the parent (App) component, and my understanding is that I should do that inside setup method like so: const myRef = ref(null)
But alas, myRef.value is forever null
codesandbox demo
Entry file:
import { createApp } from 'vue'
import App from "./App.vue";
createApp(App).mount('#app')
Parent App.vue:
<template>
<Foo ref="myRef"/>
</template>
<script>
import { onMounted, ref } from 'vue'
import Foo from "./components/Foo.vue"
export default {
name: "App",
components: { Foo },
setup(props) {
const myRef = ref(null)
onMounted(()=>{
console.log(111, myRef.value)
})
return {
myRef
}
}
}
</script>
Child component Foo.vue:
<template>
<div>xxx</div>
</template>
<script>
export default {
name: "Foo",
mounted() {
this.test = 123
}
}
</script>
if I place ref="myRef" on the <h1> it works, but I need it to work on my custom component so I could access things there...
Now I don't know jack**** about vue, and there's a TON of very conflicting confusing information out there.. I am using version v3 in my demo and the App component is authored in that manner (from what little I could understand from the insanity out there) but my component tagify.vue is authored in v2 fashion - for wider audience usage.
UPDATE - after lots of wasted hours
it's codesandbox console bug! it's wrongly displaying it as null
I trusted their console too much not to open the browser's one (due to performance reasons as it greatly slows my computer on that specific website).