I have a vue component which is as follows and in the child template I have a text input which I want to use v-model to link it to a var in the parent. But its not working. How would I be able to achieve this?
I'm currently using Vue.js 1.23 (needing to use it for certain reasons so upgrading isn't an option)
Thank you
// this is in my Vue app
textWidget: ''
// this is called directly in the page.html
<text-widget v-show="getCurrentWidgetType() == 'text-widget'" :textWidget="textWidget"></text-widget>
// declaring the component just before my main vue app
Vue.component('text-widget', {
template: `{% include('templates/widgets/text.html.twig') %}`,
date: function () {
return {
textWidget:textWidget
}
}
})
Update :
// declared just before my Vue app
Vue.component('text-widget', {
template: `{% include('templates/widgets/text.html.twig') %}`,
props: ['textwidgetmodel']
})
// text input in the component child
<input type="text" v-model="textwidgetmodel">
// html in the main html page
// this input was just for testing. This confirmed that the props binding did indeed work,
// the only problem is it seems to be a one way binding from parent to child.
// I assume this because when I change the value with the text input below then it changes the value even in the component element.
// But when a value in inputted into the child text input nothing happens to the value in the partent
<input type="text" v-model="textWidget" />
<text-widget v-show="getCurrentWidgetType() == 'text-widget'" :textwidgetmodel=textWidget></text-widget>