Does anybody here have experience with Vue 3 Render Function? I don’t know how to set up the v-model and on clicks, the documentation on Vue 3 somewhat kinda useless and lacks practical usage examples.
Maybe someone has a sample code?
Advertisement
Answer
If you want to emulate the v-model
directive in the render function try something like :
JavaScript
x
8
1
h('input', {
2
value: this.test,
3
onInput:(e)=> {
4
this.test = e.target.value
5
}
6
7
})
8
which is equivalent to <input v-model="test" />
JavaScript
1
23
23
1
const {
2
createApp,
3
h
4
} = Vue;
5
const App = {
6
data() {
7
return {
8
test: "Test"
9
}
10
},
11
render() {
12
return h('div', {}, [h('input', {
13
value: this.test,
14
onInput:(e)=> {
15
this.test = e.target.value
16
17
}
18
19
}),h("h4",this.test)])
20
}
21
}
22
const app = createApp(App)
23
app.mount('#app')
JavaScript
1
4
1
<script src="https://unpkg.com/vue@3.0.0-rc.11/dist/vue.global.prod.js"></script>
2
3
<div id="app">
4
</div>