-
-
Notifications
You must be signed in to change notification settings - Fork 3
Home
Fatih Koca edited this page Nov 27, 2019
·
27 revisions
It is a XHR plugin that works in specific features for Vue.js 2.x and and above versions. It has many similar features with jQuery
's ajax()
and Angular
's $http()
.
It allows you to write more tidy code by solving many of the most common features used by developers in the core.
Some examples:
- One of the most common problems is the problem of sending dublicate requests at the same time. Vue.js Ajax solve it easily:
preventDuplicate: true
. - File uploading with
Ajax
(XMLHttpRequest
) can sometimes require you to write extra code. But it's very simple to do it withVue.js Ajax
:fileInputs: [FILE_INPUT_ELEMENT_1, FILE_INPUT_ELEMENT_2, ...]
- There is also ComponentShifter which solves a different task. With componentShifter() you can load (with
Vue.ajax
) and render yourVue template
(html) in your application by dynamic & asyncVue.component()
. You can also add components and run them nested.
Vue.ajax.get(string url[, object data] [,object configurations]) .then(function success[, function error])
Property | Required | Type | Description |
---|---|---|---|
url | Yes | String | A string containing the URL to which the request is sent. |
data | No | Object | A plain object that is sent to the server with the request. |
configurations | No | Object | A set of key/value pairs that configure the Vue.ajax request. |
- Delete method:
Vue.ajax.delete(...)
- Get method:
Vue.ajax.get(...)
- Head method:
Vue.ajax.head(...)
- Jsonp method:
Vue.ajax.jsonp(...)
- Patch method:
Vue.ajax.patch(...)
- Post method:
Vue.ajax.post(...)
- Put method:
Vue.ajax.put(...)
All of the above methods are a shorthand method of the Vue.ajax()
:
Vue.ajax({
url: "http://example.com",
method: "get" // post, put, patch, delete, head, jsonp
}).then(function(response) {
console.log("Success", response.data)
}, function(response) {
console.log("Error", response.statusText)
})