Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

oolongtea's avatar

form submit in vue.js

Hi, I've been struggling to find a way to submit a form in Vue. In Jquery, I can use form id and submit like so.

$( "#target" ).submit();

How can I do that in Vue? for example, here's my opening form.

<form ref:form="" method="POST" action="admin/item" accept-charset="UTF-8" role="form" id="form-create" class="form-horizontal">

Thanks!

0 likes
3 replies
tisuchi's avatar

You need to use axios for that. Use cdn for axios.

this.$http.post(Pass your params).then((response) => {
                    
}, (response) => {
    // error callback
});
1 like
Lars-Janssen's avatar

Your form:

<form @click.prevent="submitMethod">

Then your input field in the form contains a v-model:

<input type="text" v-model="yourData">

Then in your vue component:

submitMethod() {
     axios.post('/afdelingen', this.yourData).then((data) => {
            //Do here what you want. 
     });
}
2 likes
Jaytee's avatar
Jaytee
Best Answer
Level 39

@tisuchi @lars6 Pretty sure OP just wants to submit the form from something like a button outside, not do an Ajax request.

OP:

document.querySelector('#myform').submit(); // will do the same as $('#myform').submit();

// or if you want to do an Ajax request, follow what the other users have done above

Please or to participate in this conversation.