I'm attempting to establish a watcher in Vue.js to duplicate an input conditionally. Using the value property, I keep experiencing null references, will someone elaborate to why this may be so I may better understand the issue?
My HTML:
<div id="company-form">
<label>Name</label>
<input v-model="legalName" type="text"/>
<label>Name To Call</label>
<input v-model="communicationsName" />
</div>
My Vue code:
new Vue({
el: '#company-form',
data: {
legalName: null,
communicationsName: null,
},
watch: {
legalName: function() {
if (!this.communicationsName.value || this.legalName.value == this.communicationsName.value) {
this.communicationsName.value = this.legalName.value;
}
}
},
});
Console Errors:
[Vue warn]: Error in callback for watcher "legalName": "TypeError: Cannot read property 'value' of null"
vue.js:18 TypeError: Cannot read property 'value' of null