Add forwardRef API to make it possible let component handle ref itself #258
Open
Description
When we pass ref to a component or DOM element, the ref will point to component instance or DOM element which handled by Vue internally.
In some case we may want to handle ref ourself. For example, if I want wrapper a Input component but just want to handle some logic when use input. I maight do:
const Input = defineComponent({
setup() {
const localHandleInput = () => {}
return () => <input onInput={localHandleInput} />
}
})
At this case I don't want the ref passed to the component just point to the component instance because it's nothing there. I want to point the ref to the real input DOM element, by now I did not find any way to implement this.
Maybe we need to add some api like forwardRef
in React, or add an forwardRef
option when defineComponent. Then Vue pass the ref handler into the setup
method, so that we can handle ref ourself.
const Input = defineComponent({
forwardFef: true,
setup(props, { ref }) {
const localHandleInput = () => {}
return () => <input onInput={localHandleInput} ref={ref} />
}
})
Metadata
Assignees
Labels
No labels