I have a form and I should send data to the server by API, but then I want to redirect to the page that I want. Because I use Vue-router, I want to use :to="", it redirects, but doesn’t send data.
<form :action="`/my/api/`" method="post">
<input name="file" v-model="form.file" type="file" />
<input name="name" v-model="form.name" label="Name"/>
<btn label="send" type="submit" v-close-popup/>
</form>
How this issue could be solved?
2
Answers
You can handle this programmatically by putting all the actions you want to execute on submit into a single method and have the form call that method on submit. The below code includes some simplifications and is not the exact code necessary to complete your task. It is just meant to provide a general idea of what to do.
To achieve the requirement, You have to follow these steps :
action
in the form, You should invoke a method on submit which will responsible to make an API call with the form data.Template code should be :
In script :