I'm working on a complex app so I simplify my question.
I have a input component located in the InputFile.vue
and a FormFile.vue
. I import the InputFile into the Form and after the user uploads a file to the inputfield and send the post request, I want to send the file with axios to the backend.
<!--INPUTFILE-->
<template>
<input
:id="props.name"
:name="props.name"
type="file"
:ref="props.name"
/>
</template>
// ...
<script setup>
import { defineProps, ref } from "vue";
const props = defineProps({
name: String,
});
let fileName = ref("");
<!-- FORMFILE -->
<template>
<div>
<InputFile name="file" />
</div>
</template>
// ...
<script setup>
import InputFile from "@/components/InputFile";
import { ref } from "vue";
const input_file = InputFile.fileName;
axios.post('post/file', {
input_file: input_file
}).then((res) => console.log(res));
The input_file is not getting the value of the file input (from component InputFile.vue
). How can I access the input.value
from FormFile ?