Skip to content

How do I pass ref to child component? #652

@rationalthinker1

Description

@rationalthinker1

After a whole day of debugging, I found a problem with passing ref to a grandchild element in vue 3.
Basically, my setup is like this:
Form -> CustomInput -> Input

in Form, when I use ref, I want it to refer to Input.

<template>
  <custom-input ref="address"/>
</template>
<script>
setup(props, context) {
    const address = ref();
    const { initAutoComplete } = useGoogleMaps();

    onMounted(() => {
      initAutoComplete(address.value);
    });

    return {
      address,
    };
  },
</script>

Right now, the value of address.value is undefined.
How can I solve this? Please give example.

Thank you.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions