Access ref from slot in my component #14342
Unanswered
gimler
asked this question in
Help/Questions
Replies: 2 comments
|
Use Incomplete code snippet using // MyComponent.vue
<script setup>
const child = ref(), btn = ref();
provide('M',reactive({ child, btn }));
</script>// MyBtn.vue
<script setup>
const onClick = () => { }
const M = inject('M') || {};
watchEffect(()=>{ M.btn = { onClick } })
</script>You can even use HTML |
0 replies
|
Hi @gimler! Working with Vue reactivity system and compilers can sometimes present interesting edge cases. A few quick things to consider regarding this topic:
I highly recommend checking out the Vue DevTools extension to inspect the component tree and verify if the state is updating as expected. Let me know if you want to dig deeper into the specific component logic. Hope this points you in the right direction! Let me know how it goes. Happy coding! |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
I have a component that defines a slot.
When i use this component i define a ref on a child component in the default slot
i always getting
null. The form ref works.I found this hack
Why
I need to call a method from
my-child(use defineExpose) when clicking onmy-btn.Question:
Is there a better way to access the ref in the slot?
All reactions