I am trying to create a dynamic input component that will be interchangeable between the input tag and textarea. I am trying to implement this using the render function. ( https://vuejs.org/v2/guide/render-function.html#v-model ).
The problem is that the v-model works in only one way, if I change the data property directly, it updates the textarea value, but if I change or enter new data in textarea, it does not update the data property. Does anyone know how to make it work in both directions? Here is my code link for a code pen, this illustrates the problem:
const tag = Vue.component('dynamic-tag', { name: 'dynamic-tag', render(createElement) { return createElement( this.tag, { domProps: { value: this.value }, on: { input: event => { this.value = event.target.value } } }, this.$slots.default ) }, props: { tag: { type: String, required: true } } }) const app = new Vue({ el: '#app', data: { message: '' }, components: {tag} })
http://codepen.io/asolopovas/pen/OpWVxa?editors=1011
source share