Using event modifier .prevent in Vue to submit form without redirection

后端 未结 3 1520
日久生厌
日久生厌 2021-01-05 01:33

I\'m using Vue in my application and I would like to know how to submit a form but avoid redirection. According to the official Vue doc it can be achieved in the following w

3条回答
  •  感情败类
    2021-01-05 01:58

    Try @submit.prevent="myFunction()", and your button could instead be . The submit type will trigger the form to submit, and the submit.prevent will prevent the default submit behavior and execute myFunction as desired.

    This has the additional benefit of triggering form validation for required input fields!

提交回复
热议问题