diff --git a/README.md b/README.md index 35da3de8..97e41fc2 100644 --- a/README.md +++ b/README.md @@ -18,9 +18,9 @@ $ npm install vue-resource ``` ### CDN -Available on [jsdelivr](https://cdn.jsdelivr.net/npm/vue-resource@1.3.6), [unpkg](https://unpkg.com/vue-resource@1.3.6) or [cdnjs](https://cdnjs.com/libraries/vue-resource). +Available on [jsdelivr](https://cdn.jsdelivr.net/npm/vue-resource@1.4.0), [unpkg](https://unpkg.com/vue-resource@1.4.0) or [cdnjs](https://cdnjs.com/libraries/vue-resource). ```html - + ``` ## Example diff --git a/bower.json b/bower.json index 590b46a5..f9caea54 100644 --- a/bower.json +++ b/bower.json @@ -1,7 +1,7 @@ { "name": "vue-resource", "main": "dist/vue-resource.js", - "version": "1.3.6", + "version": "1.4.0", "description": "The HTTP client for Vue.js", "homepage": "https://github.com/pagekit/vue-resource", "license": "MIT", diff --git a/dist/vue-resource.common.js b/dist/vue-resource.common.js index a4986345..09c6dd15 100644 --- a/dist/vue-resource.common.js +++ b/dist/vue-resource.common.js @@ -1,5 +1,5 @@ /*! - * vue-resource v1.3.6 + * vue-resource v1.4.0 * https://github.com/pagekit/vue-resource * Released under the MIT License. */ @@ -264,11 +264,9 @@ p$1.finally = function (callback) { var ref = {}; var hasOwnProperty = ref.hasOwnProperty; - var ref$1 = []; var slice = ref$1.slice; -var debug = false; -var ntick; +var debug = false, ntick; var inBrowser = typeof window !== 'undefined'; @@ -327,8 +325,6 @@ function isString(val) { return typeof val === 'string'; } - - function isFunction(val) { return typeof val === 'function'; } @@ -827,7 +823,7 @@ function xdrClient (request) { var SUPPORTS_CORS = inBrowser && 'withCredentials' in new XMLHttpRequest(); -function cors (request, next) { +function cors (request) { if (inBrowser) { @@ -845,33 +841,28 @@ function cors (request, next) { } } - next(); } /** * Form data Interceptor. */ -function form (request, next) { +function form (request) { if (isFormData(request.body)) { - request.headers.delete('Content-Type'); - } else if (isObject(request.body) && request.emulateJSON) { - request.body = Url.params(request.body); request.headers.set('Content-Type', 'application/x-www-form-urlencoded'); } - next(); } /** * JSON Interceptor. */ -function json (request, next) { +function json (request) { var type = request.headers.get('Content-Type') || ''; @@ -879,11 +870,11 @@ function json (request, next) { request.body = JSON.stringify(request.body); } - next(function (response) { + return function (response) { return response.bodyText ? when(response.text(), function (text) { - type = response.headers.get('Content-Type') || ''; + var type = response.headers.get('Content-Type') || ''; if (type.indexOf('application/json') === 0 || isJson(text)) { @@ -901,7 +892,7 @@ function json (request, next) { }) : response; - }); + }; } function isJson(str) { @@ -970,47 +961,44 @@ function jsonpClient (request) { * JSONP Interceptor. */ -function jsonp (request, next) { +function jsonp (request) { if (request.method == 'JSONP') { request.client = jsonpClient; } - next(); } /** * Before Interceptor. */ -function before (request, next) { +function before (request) { if (isFunction(request.before)) { request.before.call(this, request); } - next(); } /** * HTTP method override Interceptor. */ -function method (request, next) { +function method (request) { if (request.emulateHTTP && /^(PUT|PATCH|DELETE)$/i.test(request.method)) { request.headers.set('X-HTTP-Method-Override', request.method); request.method = 'POST'; } - next(); } /** * Header Interceptor. */ -function header (request, next) { +function header (request) { var headers = assign({}, Http.headers.common, !request.crossOrigin ? Http.headers.custom : {}, @@ -1023,7 +1011,6 @@ function header (request, next) { } }); - next(); } /** @@ -1130,52 +1117,45 @@ function nodeClient (request) { function Client (context) { - var reqHandlers = [sendRequest], resHandlers = [], handler; + var reqHandlers = [sendRequest], resHandlers = []; if (!isObject(context)) { context = null; } function Client(request) { - return new PromiseObj(function (resolve, reject) { - - function exec() { + while (reqHandlers.length) { - handler = reqHandlers.pop(); + var handler = reqHandlers.pop(); - if (isFunction(handler)) { - handler.call(context, request, next); - } else { - warn(("Invalid interceptor of type " + (typeof handler) + ", must be a function")); - next(); - } - } + if (isFunction(handler)) { - function next(response) { + var response = (void 0), next = (void 0); - if (isFunction(response)) { + response = handler.call(context, request, function (val) { return next = val; }) || next; - resHandlers.unshift(response); + if (isObject(response)) { + return new PromiseObj(function (resolve, reject) { - } else if (isObject(response)) { + resHandlers.forEach(function (handler) { + response = when(response, function (response) { + return handler.call(context, response) || response; + }, reject); + }); - resHandlers.forEach(function (handler) { - response = when(response, function (response) { - return handler.call(context, response) || response; - }, reject); - }); + when(response, resolve, reject); - when(response, resolve, reject); + }, context); + } - return; + if (isFunction(response)) { + resHandlers.unshift(response); } - exec(); + } else { + warn(("Invalid interceptor of type " + (typeof handler) + ", must be a function")); } - - exec(); - - }, context); + } } Client.use = function (handler) { diff --git a/dist/vue-resource.esm.js b/dist/vue-resource.esm.js index fc7ea6eb..123013b7 100644 --- a/dist/vue-resource.esm.js +++ b/dist/vue-resource.esm.js @@ -1,5 +1,5 @@ /*! - * vue-resource v1.3.6 + * vue-resource v1.4.0 * https://github.com/pagekit/vue-resource * Released under the MIT License. */ @@ -262,11 +262,9 @@ p$1.finally = function (callback) { var ref = {}; var hasOwnProperty = ref.hasOwnProperty; - var ref$1 = []; var slice = ref$1.slice; -var debug = false; -var ntick; +var debug = false, ntick; var inBrowser = typeof window !== 'undefined'; @@ -325,8 +323,6 @@ function isString(val) { return typeof val === 'string'; } - - function isFunction(val) { return typeof val === 'function'; } @@ -825,7 +821,7 @@ function xdrClient (request) { var SUPPORTS_CORS = inBrowser && 'withCredentials' in new XMLHttpRequest(); -function cors (request, next) { +function cors (request) { if (inBrowser) { @@ -843,33 +839,28 @@ function cors (request, next) { } } - next(); } /** * Form data Interceptor. */ -function form (request, next) { +function form (request) { if (isFormData(request.body)) { - request.headers.delete('Content-Type'); - } else if (isObject(request.body) && request.emulateJSON) { - request.body = Url.params(request.body); request.headers.set('Content-Type', 'application/x-www-form-urlencoded'); } - next(); } /** * JSON Interceptor. */ -function json (request, next) { +function json (request) { var type = request.headers.get('Content-Type') || ''; @@ -877,11 +868,11 @@ function json (request, next) { request.body = JSON.stringify(request.body); } - next(function (response) { + return function (response) { return response.bodyText ? when(response.text(), function (text) { - type = response.headers.get('Content-Type') || ''; + var type = response.headers.get('Content-Type') || ''; if (type.indexOf('application/json') === 0 || isJson(text)) { @@ -899,7 +890,7 @@ function json (request, next) { }) : response; - }); + }; } function isJson(str) { @@ -968,47 +959,44 @@ function jsonpClient (request) { * JSONP Interceptor. */ -function jsonp (request, next) { +function jsonp (request) { if (request.method == 'JSONP') { request.client = jsonpClient; } - next(); } /** * Before Interceptor. */ -function before (request, next) { +function before (request) { if (isFunction(request.before)) { request.before.call(this, request); } - next(); } /** * HTTP method override Interceptor. */ -function method (request, next) { +function method (request) { if (request.emulateHTTP && /^(PUT|PATCH|DELETE)$/i.test(request.method)) { request.headers.set('X-HTTP-Method-Override', request.method); request.method = 'POST'; } - next(); } /** * Header Interceptor. */ -function header (request, next) { +function header (request) { var headers = assign({}, Http.headers.common, !request.crossOrigin ? Http.headers.custom : {}, @@ -1021,7 +1009,6 @@ function header (request, next) { } }); - next(); } /** @@ -1128,52 +1115,45 @@ function nodeClient (request) { function Client (context) { - var reqHandlers = [sendRequest], resHandlers = [], handler; + var reqHandlers = [sendRequest], resHandlers = []; if (!isObject(context)) { context = null; } function Client(request) { - return new PromiseObj(function (resolve, reject) { - - function exec() { + while (reqHandlers.length) { - handler = reqHandlers.pop(); + var handler = reqHandlers.pop(); - if (isFunction(handler)) { - handler.call(context, request, next); - } else { - warn(("Invalid interceptor of type " + (typeof handler) + ", must be a function")); - next(); - } - } + if (isFunction(handler)) { - function next(response) { + var response = (void 0), next = (void 0); - if (isFunction(response)) { + response = handler.call(context, request, function (val) { return next = val; }) || next; - resHandlers.unshift(response); + if (isObject(response)) { + return new PromiseObj(function (resolve, reject) { - } else if (isObject(response)) { + resHandlers.forEach(function (handler) { + response = when(response, function (response) { + return handler.call(context, response) || response; + }, reject); + }); - resHandlers.forEach(function (handler) { - response = when(response, function (response) { - return handler.call(context, response) || response; - }, reject); - }); + when(response, resolve, reject); - when(response, resolve, reject); + }, context); + } - return; + if (isFunction(response)) { + resHandlers.unshift(response); } - exec(); + } else { + warn(("Invalid interceptor of type " + (typeof handler) + ", must be a function")); } - - exec(); - - }, context); + } } Client.use = function (handler) { diff --git a/dist/vue-resource.js b/dist/vue-resource.js index 60750728..56533ca7 100644 --- a/dist/vue-resource.js +++ b/dist/vue-resource.js @@ -1,5 +1,5 @@ /*! - * vue-resource v1.3.6 + * vue-resource v1.4.0 * https://github.com/pagekit/vue-resource * Released under the MIT License. */ @@ -268,11 +268,9 @@ p$1.finally = function (callback) { var ref = {}; var hasOwnProperty = ref.hasOwnProperty; - var ref$1 = []; var slice = ref$1.slice; -var debug = false; -var ntick; +var debug = false, ntick; var inBrowser = typeof window !== 'undefined'; @@ -331,8 +329,6 @@ function isString(val) { return typeof val === 'string'; } - - function isFunction(val) { return typeof val === 'function'; } @@ -831,7 +827,7 @@ function xdrClient (request) { var SUPPORTS_CORS = inBrowser && 'withCredentials' in new XMLHttpRequest(); -function cors (request, next) { +function cors (request) { if (inBrowser) { @@ -849,33 +845,28 @@ function cors (request, next) { } } - next(); } /** * Form data Interceptor. */ -function form (request, next) { +function form (request) { if (isFormData(request.body)) { - request.headers.delete('Content-Type'); - } else if (isObject(request.body) && request.emulateJSON) { - request.body = Url.params(request.body); request.headers.set('Content-Type', 'application/x-www-form-urlencoded'); } - next(); } /** * JSON Interceptor. */ -function json (request, next) { +function json (request) { var type = request.headers.get('Content-Type') || ''; @@ -883,11 +874,11 @@ function json (request, next) { request.body = JSON.stringify(request.body); } - next(function (response) { + return function (response) { return response.bodyText ? when(response.text(), function (text) { - type = response.headers.get('Content-Type') || ''; + var type = response.headers.get('Content-Type') || ''; if (type.indexOf('application/json') === 0 || isJson(text)) { @@ -905,7 +896,7 @@ function json (request, next) { }) : response; - }); + }; } function isJson(str) { @@ -974,47 +965,44 @@ function jsonpClient (request) { * JSONP Interceptor. */ -function jsonp (request, next) { +function jsonp (request) { if (request.method == 'JSONP') { request.client = jsonpClient; } - next(); } /** * Before Interceptor. */ -function before (request, next) { +function before (request) { if (isFunction(request.before)) { request.before.call(this, request); } - next(); } /** * HTTP method override Interceptor. */ -function method (request, next) { +function method (request) { if (request.emulateHTTP && /^(PUT|PATCH|DELETE)$/i.test(request.method)) { request.headers.set('X-HTTP-Method-Override', request.method); request.method = 'POST'; } - next(); } /** * Header Interceptor. */ -function header (request, next) { +function header (request) { var headers = assign({}, Http.headers.common, !request.crossOrigin ? Http.headers.custom : {}, @@ -1027,7 +1015,6 @@ function header (request, next) { } }); - next(); } /** @@ -1134,52 +1121,45 @@ function nodeClient (request) { function Client (context) { - var reqHandlers = [sendRequest], resHandlers = [], handler; + var reqHandlers = [sendRequest], resHandlers = []; if (!isObject(context)) { context = null; } function Client(request) { - return new PromiseObj(function (resolve, reject) { - - function exec() { + while (reqHandlers.length) { - handler = reqHandlers.pop(); + var handler = reqHandlers.pop(); - if (isFunction(handler)) { - handler.call(context, request, next); - } else { - warn(("Invalid interceptor of type " + (typeof handler) + ", must be a function")); - next(); - } - } + if (isFunction(handler)) { - function next(response) { + var response = (void 0), next = (void 0); - if (isFunction(response)) { + response = handler.call(context, request, function (val) { return next = val; }) || next; - resHandlers.unshift(response); + if (isObject(response)) { + return new PromiseObj(function (resolve, reject) { - } else if (isObject(response)) { + resHandlers.forEach(function (handler) { + response = when(response, function (response) { + return handler.call(context, response) || response; + }, reject); + }); - resHandlers.forEach(function (handler) { - response = when(response, function (response) { - return handler.call(context, response) || response; - }, reject); - }); + when(response, resolve, reject); - when(response, resolve, reject); + }, context); + } - return; + if (isFunction(response)) { + resHandlers.unshift(response); } - exec(); + } else { + warn(("Invalid interceptor of type " + (typeof handler) + ", must be a function")); } - - exec(); - - }, context); + } } Client.use = function (handler) { diff --git a/dist/vue-resource.min.js b/dist/vue-resource.min.js index c73a93f4..9eea0a2f 100644 --- a/dist/vue-resource.min.js +++ b/dist/vue-resource.min.js @@ -1,7 +1,7 @@ /*! - * vue-resource v1.3.6 + * vue-resource v1.4.0 * https://github.com/pagekit/vue-resource * Released under the MIT License. */ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.VueResource=e()}(this,function(){"use strict";var t=2;function e(e){this.state=t,this.value=void 0,this.deferred=[];var n=this;try{e(function(t){n.resolve(t)},function(t){n.reject(t)})}catch(t){n.reject(t)}}e.reject=function(t){return new e(function(e,n){n(t)})},e.resolve=function(t){return new e(function(e,n){e(t)})},e.all=function(t){return new e(function(n,o){var r=0,i=[];function s(e){return function(o){i[e]=o,(r+=1)===t.length&&n(i)}}0===t.length&&n(i);for(var u=0;u=200&&u<300,this.status=u||0,this.statusText=a||"",this.headers=new H(s),this.body=t,d(t)?this.bodyText=t:"undefined"!=typeof Blob&&t instanceof Blob&&(this.bodyBlob=t,(0===(r=t).type.indexOf("text")||-1!==r.type.indexOf("json"))&&(this.bodyText=(n=t,new o(function(t){var e=new FileReader;e.readAsText(n),e.onload=function(){t(e.result)}}))))};B.prototype.blob=function(){return v(this.bodyBlob)},B.prototype.text=function(){return v(this.bodyText)},B.prototype.json=function(){return v(this.text(),function(t){return JSON.parse(t)})},Object.defineProperty(B.prototype,"data",{get:function(){return this.body},set:function(t){this.body=t}});var M=function(t){var e;this.body=null,this.params={},w(this,t,{method:(e=t.method||"GET",e?e.toUpperCase():"")}),this.headers instanceof H||(this.headers=new H(this.headers))};M.prototype.getUrl=function(){return $(this)},M.prototype.getBody=function(){return this.body},M.prototype.respondWith=function(t,e){return new B(t,w(e||{},{url:this.getUrl()}))};var N={"Content-Type":"application/json;charset=utf-8"};function D(t){var e=this||{},n=I(e.$vm);return function(t){u.call(arguments,1).forEach(function(e){for(var n in e)void 0===t[n]&&(t[n]=e[n])})}(t||{},e.$options,D.options),D.interceptors.forEach(function(t){d(t)&&(t=D.interceptor[t]),l(t)&&n.use(t)}),n(new M(t)).then(function(t){return t.ok?t:o.reject(t)},function(t){var e;return t instanceof Error&&(e=t,"undefined"!=typeof console&&console.error(e)),o.reject(t)})}function J(t,e,n,o){var r=this||{},i={};return g(n=w({},J.actions,n),function(n,s){n=T({url:t,params:w({},e)},o,n),i[s]=function(){return(r.$http||D)(function(t,e){var n,o=w({},t),r={};switch(e.length){case 2:r=e[0],n=e[1];break;case 1:/^(POST|PUT|PATCH)$/i.test(o.method)?n=e[0]:r=e[0];break;case 0:break;default:throw"Expected up to 2 arguments [params, body], got "+e.length+" arguments"}return o.body=n,o.params=w({},o.params,r),o}(n,arguments))}}),i}function W(t){var e,n,r;W.installed||(n=(e=t).config,r=e.nextTick,i=r,a=n.debug||!n.silent,t.url=$,t.http=D,t.resource=J,t.Promise=o,Object.defineProperties(t.prototype,{$url:{get:function(){return b(t.url,this,this.$options.url)}},$http:{get:function(){return b(t.http,this,this.$options.http)}},$resource:{get:function(){return t.resource.bind(this)}},$promise:{get:function(){var e=this;return function(n){return new t.Promise(n,e)}}}}))}return D.options={},D.headers={put:N,post:N,patch:N,delete:N,common:{Accept:"application/json, text/plain, */*"},custom:{}},D.interceptor={before:function(t,e){l(t.before)&&t.before.call(this,t),e()},method:function(t,e){t.emulateHTTP&&/^(PUT|PATCH|DELETE)$/i.test(t.method)&&(t.headers.set("X-HTTP-Method-Override",t.method),t.method="POST"),e()},jsonp:function(t,e){"JSONP"==t.method&&(t.client=A),e()},json:function(t,e){var n=t.headers.get("Content-Type")||"";m(t.body)&&0===n.indexOf("application/json")&&(t.body=JSON.stringify(t.body)),e(function(t){return t.bodyText?v(t.text(),function(e){if(0===(n=t.headers.get("Content-Type")||"").indexOf("application/json")||(r=(o=e).match(/^\s*(\[|\{)/))&&{"[":/]\s*$/,"{":/}\s*$/}[r[1]].test(o))try{t.body=JSON.parse(e)}catch(e){t.body=null}else t.body=e;var o,r;return t}):t})},form:function(t,e){var n;n=t.body,"undefined"!=typeof FormData&&n instanceof FormData?t.headers.delete("Content-Type"):m(t.body)&&t.emulateJSON&&(t.body=$.params(t.body),t.headers.set("Content-Type","application/x-www-form-urlencoded")),e()},header:function(t,e){g(w({},D.headers.common,t.crossOrigin?{}:D.headers.custom,D.headers[p(t.method)]),function(e,n){t.headers.has(n)||t.headers.set(n,e)}),e()},cors:function(t,e){if(c){var n=$.parse(location.href),o=$.parse(t.getUrl());o.protocol===n.protocol&&o.host===n.host||(t.crossOrigin=!0,t.emulateHTTP=!1,R||(t.client=U))}e()}},D.interceptors=["before","method","jsonp","json","form","header","cors"],["get","delete","head","jsonp"].forEach(function(t){D[t]=function(e,n){return this(w(n||{},{url:e,method:t}))}}),["post","put","patch"].forEach(function(t){D[t]=function(e,n,o){return this(w(o||{},{url:e,method:t,body:n}))}}),J.actions={get:{method:"GET"},save:{method:"POST"},query:{method:"GET"},update:{method:"PUT"},remove:{method:"DELETE"},delete:{method:"DELETE"}},"undefined"!=typeof window&&window.Vue&&window.Vue.use(W),W}); \ No newline at end of file +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.VueResource=e()}(this,function(){"use strict";var t=2;function e(e){this.state=t,this.value=void 0,this.deferred=[];var n=this;try{e(function(t){n.resolve(t)},function(t){n.reject(t)})}catch(t){n.reject(t)}}e.reject=function(t){return new e(function(e,n){n(t)})},e.resolve=function(t){return new e(function(e,n){e(t)})},e.all=function(t){return new e(function(n,o){var r=0,i=[];function s(e){return function(o){i[e]=o,(r+=1)===t.length&&n(i)}}0===t.length&&n(i);for(var u=0;u=200&&a<300,this.status=a||0,this.statusText=c||"",this.headers=new q(u),this.body=t,d(t)?this.bodyText=t:(i=t,"undefined"!=typeof Blob&&i instanceof Blob&&(this.bodyBlob=t,(0===(r=t).type.indexOf("text")||-1!==r.type.indexOf("json"))&&(this.bodyText=(n=t,new o(function(t){var e=new FileReader;e.readAsText(n),e.onload=function(){t(e.result)}})))))};L.prototype.blob=function(){return v(this.bodyBlob)},L.prototype.text=function(){return v(this.bodyText)},L.prototype.json=function(){return v(this.text(),function(t){return JSON.parse(t)})},Object.defineProperty(L.prototype,"data",{get:function(){return this.body},set:function(t){this.body=t}});var B=function(t){var e;this.body=null,this.params={},w(this,t,{method:(e=t.method||"GET",e?e.toUpperCase():"")}),this.headers instanceof q||(this.headers=new q(this.headers))};B.prototype.getUrl=function(){return $(this)},B.prototype.getBody=function(){return this.body},B.prototype.respondWith=function(t,e){return new L(t,w(e||{},{url:this.getUrl()}))};var M={"Content-Type":"application/json;charset=utf-8"};function N(t){var e=this||{},n=function(t){var e=[I],n=[];function r(r){for(;e.length;){var i=e.pop();if(l(i)){var s=void 0,u=void 0;if(m(s=i.call(t,r,function(t){return u=t})||u))return new o(function(e,o){n.forEach(function(e){s=v(s,function(n){return e.call(t,n)||n},o)}),v(s,e,o)},t);l(s)&&n.unshift(s)}else c="Invalid interceptor of type "+typeof i+", must be a function","undefined"!=typeof console&&a&&console.warn("[VueResource warn]: "+c)}var c}return m(t)||(t=null),r.use=function(t){e.push(t)},r}(e.$vm);return function(t){u.call(arguments,1).forEach(function(e){for(var n in e)void 0===t[n]&&(t[n]=e[n])})}(t||{},e.$options,N.options),N.interceptors.forEach(function(t){d(t)&&(t=N.interceptor[t]),l(t)&&n.use(t)}),n(new B(t)).then(function(t){return t.ok?t:o.reject(t)},function(t){var e;return t instanceof Error&&(e=t,"undefined"!=typeof console&&console.error(e)),o.reject(t)})}function D(t,e,n,o){var r=this||{},i={};return g(n=w({},D.actions,n),function(n,s){n=T({url:t,params:w({},e)},o,n),i[s]=function(){return(r.$http||N)(function(t,e){var n,o=w({},t),r={};switch(e.length){case 2:r=e[0],n=e[1];break;case 1:/^(POST|PUT|PATCH)$/i.test(o.method)?n=e[0]:r=e[0];break;case 0:break;default:throw"Expected up to 2 arguments [params, body], got "+e.length+" arguments"}return o.body=n,o.params=w({},o.params,r),o}(n,arguments))}}),i}function J(t){var e,n,r;J.installed||(n=(e=t).config,r=e.nextTick,i=r,a=n.debug||!n.silent,t.url=$,t.http=N,t.resource=D,t.Promise=o,Object.defineProperties(t.prototype,{$url:{get:function(){return b(t.url,this,this.$options.url)}},$http:{get:function(){return b(t.http,this,this.$options.http)}},$resource:{get:function(){return t.resource.bind(this)}},$promise:{get:function(){var e=this;return function(n){return new t.Promise(n,e)}}}}))}return N.options={},N.headers={put:M,post:M,patch:M,delete:M,common:{Accept:"application/json, text/plain, */*"},custom:{}},N.interceptor={before:function(t){l(t.before)&&t.before.call(this,t)},method:function(t){t.emulateHTTP&&/^(PUT|PATCH|DELETE)$/i.test(t.method)&&(t.headers.set("X-HTTP-Method-Override",t.method),t.method="POST")},jsonp:function(t){"JSONP"==t.method&&(t.client=A)},json:function(t){var e=t.headers.get("Content-Type")||"";return m(t.body)&&0===e.indexOf("application/json")&&(t.body=JSON.stringify(t.body)),function(t){return t.bodyText?v(t.text(),function(e){var n,o;if(0===(t.headers.get("Content-Type")||"").indexOf("application/json")||(o=(n=e).match(/^\s*(\[|\{)/))&&{"[":/]\s*$/,"{":/}\s*$/}[o[1]].test(n))try{t.body=JSON.parse(e)}catch(e){t.body=null}else t.body=e;return t}):t}},form:function(t){var e;e=t.body,"undefined"!=typeof FormData&&e instanceof FormData?t.headers.delete("Content-Type"):m(t.body)&&t.emulateJSON&&(t.body=$.params(t.body),t.headers.set("Content-Type","application/x-www-form-urlencoded"))},header:function(t){g(w({},N.headers.common,t.crossOrigin?{}:N.headers.custom,N.headers[p(t.method)]),function(e,n){t.headers.has(n)||t.headers.set(n,e)})},cors:function(t){if(c){var e=$.parse(location.href),n=$.parse(t.getUrl());n.protocol===e.protocol&&n.host===e.host||(t.crossOrigin=!0,t.emulateHTTP=!1,R||(t.client=U))}}},N.interceptors=["before","method","jsonp","json","form","header","cors"],["get","delete","head","jsonp"].forEach(function(t){N[t]=function(e,n){return this(w(n||{},{url:e,method:t}))}}),["post","put","patch"].forEach(function(t){N[t]=function(e,n,o){return this(w(o||{},{url:e,method:t,body:n}))}}),D.actions={get:{method:"GET"},save:{method:"POST"},query:{method:"GET"},update:{method:"PUT"},remove:{method:"DELETE"},delete:{method:"DELETE"}},"undefined"!=typeof window&&window.Vue&&window.Vue.use(J),J}); \ No newline at end of file diff --git a/package.json b/package.json index 241b0c68..61f829ea 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vue-resource", - "version": "1.3.6", + "version": "1.4.0", "main": "dist/vue-resource.common.js", "module": "dist/vue-resource.esm.js", "unpkg": "dist/vue-resource.min.js",