admin管理员组文章数量:1415092
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?
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?
Share Improve this question edited Apr 12, 2021 at 19:23 James Z 12.3k10 gold badges27 silver badges47 bronze badges asked Apr 12, 2021 at 13:10 Skeeith22Skeeith22 3164 silver badges17 bronze badges 6- please share what have you tried so far, or an example made using template syntax that you want to convert it to a render functioon – Boussadjra Brahim Commented Apr 12, 2021 at 13:11
- All you need is in the docs. Show us what have you tried so far. – Adam Orłowski Commented Apr 12, 2021 at 13:13
- 1 Vue 3 has this doc. v3.vuejs/guide/render-function.html#v-model – Skeeith22 Commented Apr 12, 2021 at 13:24
- I've tried A LOT OF THINGS already. @BoussadjraBrahim just a simple input text with a v-model functionality, that's it. – Skeeith22 Commented Apr 12, 2021 at 13:25
- pretty sure the docs aren't clear as it supposed to be @AdamOrlov Running JSX is a shortcut and pretty much solves my problem BUT I wanted to know how to write this thing without relying on JSX. – Skeeith22 Commented Apr 12, 2021 at 13:25
2 Answers
Reset to default 3If you want to emulate the v-model
directive in the render function try something like :
h('input', {
value: this.test,
onInput:(e)=> {
this.test = e.target.value
}
})
which is equivalent to <input v-model="test" />
const {
createApp,
h
} = Vue;
const App = {
data() {
return {
test: "Test"
}
},
render() {
return h('div', {}, [h('input', {
value: this.test,
onInput:(e)=> {
this.test = e.target.value
}
}),h("h4",this.test)])
}
}
const app = createApp(App)
app.mount('#app')
<script src="https://unpkg./[email protected]/dist/vue.global.prod.js"></script>
<div id="app">
</div>
@Boussadjra Brahim
render() {
self = this; // Added this
return h('div', {}, h('input', {
value: this.test,
onInput(e) {
self.test = e.target.value // Change this.test to self.test
}
}))
}
Thank you for this, I don't know why onKeyUp didn't work but onInput did.
本文标签: javascriptVue 3 Render Function how to set up vmodel and onClicksStack Overflow
版权声明:本文标题:javascript - Vue 3 Render Function how to set up v-model and onClicks - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745177044a2646287.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论