0

I'm trying to emit a FormData object in from child component to parent Component. Here is some code what I'm trying:

Child Component

onAddFile(error, file) {
  const formData = new FormData();
  formData.append(this.fileName, file.file);
  console.log(...formData); // here it show the output
  this.$emit("input", formData);  // not working here
}

I am trying to store the emitted data in a object in parent component. but it just stores a String. In the case of console.log it shows following. enter image description here

How to solve it ?

3
  • How are you handling the $emit("input") function in parent page?? Commented Feb 23, 2021 at 11:26
  • by v-model binding Commented Feb 23, 2021 at 11:27
  • can you show some code from parent component of how you are handling the data? Commented Feb 23, 2021 at 11:28

1 Answer 1

1

In your parent, you could watch for the emit event with (to at least debug)

<div @input="captureFormData"></div>
methods: {
  captureFormData(capturedData) {
    console.log('captured here', capturedData)
  }
}

You could also use the .sync modifier but it is gently deprecated in Vue3 AFAIK.

Here is a reminder on how v-model works on components

<input v-model="searchText">
<!-- is equivalent to -->
<input
  :value="searchText"
  @input="searchText = $event.target.value"
>

So, if your logic works with this snippet, it may work here too.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.