|
1 | 1 | /** |
2 | | - * vue-resource v0.1.10 |
| 2 | + * vue-resource v0.1.11 |
3 | 3 | * https://github.com/vuejs/vue-resource |
4 | 4 | * Released under the MIT License. |
5 | 5 | */ |
@@ -340,12 +340,13 @@ return /******/ (function(modules) { // webpackBootstrap |
340 | 340 | var _ = __webpack_require__(2); |
341 | 341 | var xhr = __webpack_require__(4); |
342 | 342 | var jsonp = __webpack_require__(6); |
343 | | - var jsonType = {'Content-Type': 'application/json;charset=utf-8'}; |
| 343 | + var Promise = __webpack_require__(5); |
344 | 344 |
|
345 | 345 | module.exports = function (Vue) { |
346 | 346 |
|
347 | 347 | var Url = Vue.url; |
348 | 348 | var originUrl = Url.parse(location.href); |
| 349 | + var jsonType = {'Content-Type': 'application/json;charset=utf-8'}; |
349 | 350 |
|
350 | 351 | function Http(url, options) { |
351 | 352 |
|
@@ -396,22 +397,20 @@ return /******/ (function(modules) { // webpackBootstrap |
396 | 397 | options.data = JSON.stringify(options.data); |
397 | 398 | } |
398 | 399 |
|
399 | | - promise = (options.method.toLowerCase() == 'jsonp' ? jsonp : xhr).call(self, self.$url || Url, options); |
400 | | - |
401 | | - promise.then(transformResponse, transformResponse); |
| 400 | + promise = (options.method.toLowerCase() == 'jsonp' ? jsonp : xhr).call(self, self.$url || Url, options).then(transformResponse, transformResponse); |
402 | 401 |
|
403 | 402 | promise.success = function (fn) { |
404 | 403 |
|
405 | 404 | promise.then(function (response) { |
406 | 405 | fn.call(self, response.data, response.status, response); |
407 | | - }, function () {}); |
| 406 | + }); |
408 | 407 |
|
409 | 408 | return promise; |
410 | 409 | }; |
411 | 410 |
|
412 | 411 | promise.error = function (fn) { |
413 | 412 |
|
414 | | - promise.catch(function (response) { |
| 413 | + promise.then(undefined, function (response) { |
415 | 414 | fn.call(self, response.data, response.status, response); |
416 | 415 | }); |
417 | 416 |
|
@@ -448,6 +447,7 @@ return /******/ (function(modules) { // webpackBootstrap |
448 | 447 | response.data = response.responseText; |
449 | 448 | } |
450 | 449 |
|
| 450 | + return response.ok ? response : Promise.reject(response); |
451 | 451 | } |
452 | 452 |
|
453 | 453 | function crossOrigin(url) { |
@@ -532,27 +532,17 @@ return /******/ (function(modules) { // webpackBootstrap |
532 | 532 |
|
533 | 533 | request.onreadystatechange = function () { |
534 | 534 |
|
535 | | - if (this.readyState === 4) { |
| 535 | + if (request.readyState === 4) { |
536 | 536 |
|
537 | | - if (this.status >= 200 && this.status < 300) { |
538 | | - resolve(this); |
539 | | - } else { |
540 | | - reject(this); |
541 | | - } |
| 537 | + request.ok = request.status >= 200 && request.status < 300; |
| 538 | + |
| 539 | + (request.ok ? resolve : reject)(request); |
542 | 540 | } |
543 | 541 | }; |
544 | 542 |
|
545 | 543 | request.send(options.data); |
546 | 544 | }); |
547 | 545 |
|
548 | | - _.extend(promise, { |
549 | | - |
550 | | - abort: function () { |
551 | | - request.abort(); |
552 | | - } |
553 | | - |
554 | | - }); |
555 | | - |
556 | 546 | return promise; |
557 | 547 | }; |
558 | 548 |
|
@@ -786,7 +776,7 @@ return /******/ (function(modules) { // webpackBootstrap |
786 | 776 |
|
787 | 777 | module.exports = function (url, options) { |
788 | 778 |
|
789 | | - var callback = '_jsonp' + Math.random().toString(36).substr(2), script, body; |
| 779 | + var callback = '_jsonp' + Math.random().toString(36).substr(2), response = {}, script, body; |
790 | 780 |
|
791 | 781 | options.params[options.jsonp] = callback; |
792 | 782 |
|
@@ -814,9 +804,11 @@ return /******/ (function(modules) { // webpackBootstrap |
814 | 804 | event.type = 'error'; |
815 | 805 | } |
816 | 806 |
|
817 | | - var text = body ? body : event.type, status = event.type === 'error' ? 404 : 200; |
| 807 | + response.ok = event.type !== 'error'; |
| 808 | + response.status = response.ok ? 200 : 404; |
| 809 | + response.responseText = body ? body : event.type; |
818 | 810 |
|
819 | | - (status === 200 ? resolve : reject)({responseText: text, status: status}); |
| 811 | + (response.ok ? resolve : reject)(response); |
820 | 812 | }; |
821 | 813 |
|
822 | 814 | script.onload = handler; |
@@ -938,6 +930,7 @@ return /******/ (function(modules) { // webpackBootstrap |
938 | 930 | get: {method: 'get'}, |
939 | 931 | save: {method: 'post'}, |
940 | 932 | query: {method: 'get'}, |
| 933 | + update: {method: 'put'}, |
941 | 934 | remove: {method: 'delete'}, |
942 | 935 | delete: {method: 'delete'} |
943 | 936 |
|
|
0 commit comments