I am trying to use a child component with custom form inputs & emit those value to parent component. However, while I am trying to store the values in an object of parent component, One input value disapper when another input value is entered. Let me show some code:
Child Component
<template>
<input
type="text"
@input="setField($event.target.value, 'title')"
/>
<wysiwyg-input
@change="(text) => setField(text, 'content')"
/>
</template>
<script>
export default {
methods: {
setField(value, field) {
this.$emit("input", {
title: field === "title" && value,
content: field === "content" && value,
});
},
},
}
</script>
Parent Component
<template>
<FormFields v-model="blogPost" />
</template>
<script>
export default {
data() {
return {
blogPost: {},
};
},
watch: {
blogPost(val) {
console.log(val);
},
},
};
</script>
Here, when I try to input the 'content', the 'title' field become false. So how can I set the condition on child component as I can emit both input to parent component ? Or Any other idea to accomplish the same task ?
CodeSandbox link: https://codesandbox.io/s/mystifying-benz-w8wgu?file=/src/App.vue