A
A
Artem00712017-07-20 15:28:49
JavaScript
Artem0071, 2017-07-20 15:28:49

How to submit a form in VueJS?

There is a form:

<form @submit.prevent="toSend" method="POST" action="http://www.SomeAnotherSite.com">
<input v-model="param1"/>
<button type="submit">to send</button>
</form>

And the method itself:
toSend(){
    let data = {param1: this.param1}
    this.http.post('site.com', data)
        .then(res => {
            if (res.data.check == true){ 
                   //Как сделать так, чтобы форма продолжила выполняться на 'http://www.SomeAnotherSite.com'? 
                  // вот есть метод form.prevent, а есть ли обратная ей?
           }
            else 
                   console.log('some error');
    })
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Kovalsky, 2017-07-20
@lazalu68

I didn't really understand. Do you want to make a request and then submit the form? If so, then after the request, just access the form and do a native submit :

toSend() {
    let data = { param1: this.param1 };

    this.http.post('site.com', data).then(res => {
        if (res.data.check == true) {
            this.$refs.form.submit();
        } else {
            console.log('some error');
        }
    })
}

V
Vladimir Zhosan, 2017-07-20
@iaskivsky

example

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question