I have few forms in my SPA, all are submitted via ajax.
This is the pattern I use:
<form @submit.prevent="submit">...</form>
and submit()
will do something like $(form).serialize
, to send the form data.
Usually it works fine, but have a problem - a custom component like
vue-select
: http://sagalbot.github.io/vue-select/
wont work, because it does not create a form field. So I have to add it manually to the form data. This has become a source of boilerplate code, and I want to avoid that.
The question: is there any way to make vue to auto-create data members based on the v-model of the inputs. Since I don't like the idea of duplicating the property names (both in v-model and in the vue instance). That's why I submit with serialize()
, and don't use v-model, because it's easier for me to just create <input>
elements with name attribute.
Or, to make the component to actually create a form field?
In general, is there a better way to handle forms with vue? (again, without duplicating v-model and data members?)