I am writing a Vue.js component. The component renders an <input>
element. An event listener is listening to either change or input
event, according to the value of a prop.
How to write the render function with JSX?
{
props: {
lazy: Boolean,
},
render(h) {
const bindEvent = this.lazy? 'change' : 'input'
return h('input', {
attrs: {
type: 'text',
},
on: {
[bindEvent]: e => this.$emit('update', e.target.value)
},
})
},
}
I want to write something like this:
render(h) {
const bindEvent = this.lazy? 'change' : 'input'
return <input
type='text'
on={{ [bindEvent]: e => this.$emit('update', e.target.value) }}
/>
}