In vue3 I have this:
<template>
<ChildComponent>
<div>
<input type="text" v-model="myValue"/>
</div>
</ChildComponent>
</template>
Here, in the child component the slot is rendered with input field, and it is binded to the myValue from the parent component.
How could I make it working with render function instead od declarative template like above?
In my app the slot inner html comes from the api rest service, but inserting it to the slot via v-html obviously does not work.
Vue SFC Playground
You can compile your inner html to a render function.
Here's a trick: we should provide a render context to the compiled render function with
myValue. The problem that we cannot providemyValueas it is since the compiled function looks like that:As you see the problem in
So basically the ref is overwritten, not changed (
myValue.value = $event). So we need to wrap our context into a reactive, that way whenmyValuein the context is changed, our linkedmyValueref is changed too:To support the compile you should change Vue's runtime:
vite.config.js: