Skip to content
This repository was archived by the owner on Dec 1, 2023. It is now read-only.

Commit bccab11

Browse files
committed
Merge branch 'release/0.7.0'
2 parents b675df9 + 965976a commit bccab11

File tree

11 files changed

+277
-186
lines changed

11 files changed

+277
-186
lines changed

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
build
2+
docs
23
bower.json

README.md

Lines changed: 8 additions & 165 deletions
Original file line numberDiff line numberDiff line change
@@ -16,173 +16,16 @@ var Vue = require('vue');
1616
Vue.use(require('vue-resource'));
1717
```
1818

19-
### Configuration
19+
## Documentation
2020

21-
Set default values using the global configuration.
21+
- [Configuration](docs/config.md)
22+
- [HTTP Requests/Response](docs/http.md)
23+
- [Creating Resources](docs/resource.md)
2224

23-
```js
24-
Vue.http.options.root = '/root';
25-
Vue.http.headers.common['Authorization'] = 'Basic YXBpOnBhc3N3b3Jk';
26-
```
27-
28-
Set default values inside your Vue component options.
29-
30-
```js
31-
new Vue({
32-
33-
http: {
34-
root: '/root',
35-
headers: {
36-
Authorization: 'Basic YXBpOnBhc3N3b3Jk'
37-
}
38-
}
39-
40-
})
41-
```
42-
43-
## HTTP
44-
45-
The http service can be used globally `Vue.http` or in a Vue instance `this.$http`.
46-
47-
### Methods
48-
49-
* `get(url, [data], [options])`
50-
* `post(url, [data], [options])`
51-
* `put(url, [data], [options])`
52-
* `patch(url, [data], [options])`
53-
* `delete(url, [data], [options])`
54-
* `jsonp(url, [data], [options])`
55-
56-
### Options
57-
58-
* **url** - `string` - URL to which the request is sent
59-
* **method** - `string` - HTTP method (e.g. GET, POST, ...)
60-
* **data** - `Object|string` - Data to be sent as the request message data
61-
* **params** - `Object` - Parameters object to be appended as GET parameters
62-
* **headers** - `Object` - Headers object to be sent as HTTP request headers
63-
* **beforeSend** - `function(request)` - Callback function to modify the request object before it is sent
64-
* **emulateHTTP** - `boolean` - Send PUT, PATCH and DELETE requests with a HTTP POST and set the `X-HTTP-Method-Override` header
65-
* **emulateJSON** - `boolean` - Send request data as `application/x-www-form-urlencoded` content type
66-
* **xhr** - `Object` - Parameters object to be set on the native XHR object
67-
* **jsonp** - `string` - Callback function name in a JSONP request
68-
* **timeout** - `number` - Request timeout in milliseconds (`0` means no timeout)
69-
70-
71-
### Example
72-
73-
```js
74-
new Vue({
75-
76-
ready: function() {
77-
78-
// GET request
79-
this.$http.get('/someUrl').then(function (response) {
80-
81-
// get status
82-
response.status;
83-
84-
// get all headers
85-
response.headers();
86-
87-
// get 'expires' header
88-
response.headers('expires');
89-
90-
// set data on vm
91-
this.$set('someData', response.data)
92-
93-
}, function (response) {
94-
95-
// handle error
96-
});
97-
98-
}
99-
100-
})
101-
```
102-
103-
## Resource
25+
## Changelog
10426

105-
The resource service can be used globally `Vue.resource` or in a Vue instance `this.$resource`.
27+
Details changes for each release are documented in the [release notes](https://github.com/vuejs/vue-resource/releases).
10628

107-
### Methods
29+
## Contribution
10830

109-
* `resource(url, [params], [actions], [options])`
110-
111-
### Default Actions
112-
113-
```js
114-
get: {method: 'GET'},
115-
save: {method: 'POST'},
116-
query: {method: 'GET'},
117-
update: {method: 'PUT'},
118-
remove: {method: 'DELETE'},
119-
delete: {method: 'DELETE'}
120-
```
121-
122-
### Example
123-
```js
124-
new Vue({
125-
126-
ready: function() {
127-
128-
var resource = this.$resource('someItem{/id}');
129-
130-
// get item
131-
resource.get({id: 1}).then(function (response) {
132-
this.$set('item', response.item)
133-
});
134-
135-
// save item
136-
resource.save({id: 1}, {item: this.item}).then(function (response) {
137-
// handle success
138-
}, function (response) {
139-
// handle error
140-
});
141-
142-
// delete item
143-
resource.delete({id: 1}).then(function (response) {
144-
// handle success
145-
}, function (response) {
146-
// handle error
147-
});
148-
149-
}
150-
151-
})
152-
```
153-
154-
## Interceptors
155-
156-
Interceptors can be defined globally and are used for pre- and postprocessing of a request.
157-
158-
```js
159-
Vue.http.interceptors.push({
160-
161-
request: function (request) {
162-
return request;
163-
},
164-
165-
response: function (response) {
166-
return response;
167-
}
168-
169-
});
170-
```
171-
172-
A factory function can also be used.
173-
174-
```js
175-
Vue.http.interceptors.push(function () {
176-
return {
177-
178-
request: function (request) {
179-
return request;
180-
},
181-
182-
response: function (response) {
183-
return response;
184-
}
185-
186-
};
187-
});
188-
```
31+
If you find a bug or want to contribute to the code or documentation, you can help by submitting an [issue](https://github.com/vuejs/vue-resource/issues) or a pull request.

bower.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
"name": "vue-resource",
33
"main": "dist/vue-resource.js",
44
"description": "A web request service for Vue.js",
5-
"version": "0.6.1",
5+
"version": "0.7.0",
66
"homepage": "https://github.com/vuejs/vue-resource",
77
"license": "MIT",
88
"ignore": [
99
".*",
1010
"build",
11+
"docs",
1112
"package.json"
1213
]
1314
}

dist/vue-resource.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* vue-resource v0.6.1
2+
* vue-resource v0.7.0
33
* https://github.com/vuejs/vue-resource
44
* Released under the MIT License.
55
*/
@@ -715,6 +715,7 @@ return /******/ (function(modules) { // webpackBootstrap
715715
params: {},
716716
headers: {},
717717
xhr: null,
718+
upload: null,
718719
jsonp: 'callback',
719720
beforeSend: null,
720721
crossOrigin: null,
@@ -1157,14 +1158,6 @@ return /******/ (function(modules) { // webpackBootstrap
11571158

11581159
xhr.open(request.method, _.url(request), true);
11591160

1160-
if (_.isPlainObject(request.xhr)) {
1161-
_.extend(xhr, request.xhr);
1162-
}
1163-
1164-
_.each(request.headers || {}, function (value, header) {
1165-
xhr.setRequestHeader(header, value);
1166-
});
1167-
11681161
handler = function (event) {
11691162

11701163
response.data = xhr.responseText;
@@ -1175,9 +1168,24 @@ return /******/ (function(modules) { // webpackBootstrap
11751168
resolve(response);
11761169
};
11771170

1171+
xhr.timeout = 0;
11781172
xhr.onload = handler;
11791173
xhr.onabort = handler;
11801174
xhr.onerror = handler;
1175+
xhr.ontimeout = function () {};
1176+
xhr.onprogress = function () {};
1177+
1178+
if (_.isPlainObject(request.xhr)) {
1179+
_.extend(xhr, request.xhr);
1180+
}
1181+
1182+
if (_.isPlainObject(request.upload)) {
1183+
_.extend(xhr.upload, request.upload);
1184+
}
1185+
1186+
_.each(request.headers || {}, function (value, header) {
1187+
xhr.setRequestHeader(header, value);
1188+
});
11811189

11821190
xhr.send(request.data);
11831191
});

0 commit comments

Comments
 (0)