vue-vform
Vue.js 2 form component that integrates jQuery Validation and Axios.
Install
yarn add vue-vform --dev
npm install vue-vform --save-dev
Prerequisites
- Vue.js 2
- jQuery
- jQuery Validation
- Axios (optional if you want to send (automatically) an Ajax request after validation)
Usage
Define vform
component markup inside your custom component.
For example in your custom-form-component.vue
:
<!-- Your cool stuff --> Name E-mail <!-- //Your cool stuff --> Submit
In your entry app:
const Vue = // jQuery and jQuery Validationwindow$ = windowjQuery = // If you want auto form Ajax request (optional)windowaxios = VueVue const app = el: '#app'
Attributes
method (optional)
The request method (POST, PUT, DELETE, PATCH). For dynamic value use v-bind:method="myMethod"
or :method="myMethod"
.
action (optional)
The request URL.
request (optional)
If request
(Boolean) attribute is defined vform
performs an Ajax Request using Axios and a Promise object is passed to your callback. Make sure that you have Axios before.
params (optional)
The component data binding (usually FormData
or plain object {}
values) that it will send if request
option was setted. (use v-bind:param="mydata"
or :param="mydata"
property)
accept (optional)
The request Accept
header. Default: application/json
Events
@validate
Event when validation is completed. You need to pass the callback defined in your methods: ...
. A Promise object will be passed if request
attribute was defined.
Tip
Laravel v5.4 users: It's necessary to define the Axios common headers in your app.js
file. That's is useful when your use Laravel v5.4 and Passport.
axiosdefaultsheaderscommon = 'Accept': 'application/json' 'X-Requested-With': 'XMLHttpRequest' 'X-CSRF-TOKEN': LaravelcsrfToken
License
MIT license
© 2017 José Luis Quintana