Comparing version 1.3.6 to 1.3.7
/** | ||
* vxe-ajax.js v1.3.6 | ||
* vxe-ajax.js v1.3.7 | ||
* (c) 2017-2018 Xu Liangzhan | ||
@@ -8,3 +8,3 @@ * ISC License. | ||
(function (global, factory) { | ||
typeof s === 'object' && typeof module !== 'undefined' ? module.s = factory() | ||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() | ||
: typeof define === 'function' && define.amd ? define(factory) | ||
@@ -11,0 +11,0 @@ : (global.VXEAjax = factory()) |
/** | ||
* vxe-ajax.js v1.3.6 | ||
* vxe-ajax.js v1.3.7 | ||
* (c) 2017-2018 Xu Liangzhan | ||
@@ -7,2 +7,2 @@ * ISC License. | ||
*/ | ||
!function(t,e){"object"==typeof s&&"undefined"!=typeof module?module.s=e():"function"==typeof define&&define.amd?define(e):t.VXEAjax=e()}(this,function(){"use strict";function t(t,e){return"function"==typeof t?t.bind(e):t}function e(t,e){this.promise=t instanceof Promise?t:new Promise(t.bind(e)),this.context=e}return e.prototype.then=function(n,o){return new e(this.promise.then(t(n,this.context),t(o,this.context)),this.context)},e.prototype.catch=function(n){return new e(this.promise.catch(t(n,this.context)),this.context)},e.all=function(t,n){return new e(Promise.all(t),n)},e.race=function(t,n){return new e(Promise.race(t),n)},e.resolve=function(t,n){return new e(Promise.resolve(t),n)},e.reject=function(t,n){return new e(Promise.reject(t),n)},function(t,n,o){Object.defineProperty(t.prototype,"$ajax",{get:function(){return o&&(n.$context=this,n.$Promise=e),n}})}}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.VXEAjax=e()}(this,function(){"use strict";function t(t,e){return"function"==typeof t?t.bind(e):t}function e(t,e){this.promise=t instanceof Promise?t:new Promise(t.bind(e)),this.context=e}return e.prototype.then=function(n,o){return new e(this.promise.then(t(n,this.context),t(o,this.context)),this.context)},e.prototype.catch=function(n){return new e(this.promise.catch(t(n,this.context)),this.context)},e.all=function(t,n){return new e(Promise.all(t),n)},e.race=function(t,n){return new e(Promise.race(t),n)},e.resolve=function(t,n){return new e(Promise.resolve(t),n)},e.reject=function(t,n){return new e(Promise.reject(t),n)},function(t,n,o){Object.defineProperty(t.prototype,"$ajax",{get:function(){return o&&(n.$context=this,n.$Promise=e),n}})}}); |
{ | ||
"name": "vxe-ajax", | ||
"version": "1.3.6", | ||
"version": "1.3.7", | ||
"description": "VXEAjax 用于Vue全局安装 xe-ajax", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -6,8 +6,11 @@ # VXEAjax 用于Vue全局安装 xe-ajax | ||
安装完成后自动挂载在vue实例 this.$ajax | ||
安装完成后自动挂载在 vue 实例 this.$ajax | ||
## 兼容性 | ||
基于 Promise 实现,低版本浏览器使用 polyfill es6-promise.js | ||
支持 IE8+、Edge、Chrome、Firefox、Opera、Safari等... | ||
依赖原生 Promise,低版本浏览器使用 polyfill es6-promise.js | ||
![IE](https://raw.github.com/alrra/browser-logos/master/src/archive/internet-explorer_9-11/internet-explorer_9-11_48x48.png) | ![Chrome](https://raw.github.com/alrra/browser-logos/master/src/chrome/chrome_48x48.png) | ![Firefox](https://raw.github.com/alrra/browser-logos/master/src/firefox/firefox_48x48.png) | ![Opera](https://raw.github.com/alrra/browser-logos/master/src/opera/opera_48x48.png) | ![Safari](https://raw.github.com/alrra/browser-logos/master/src/safari/safari_48x48.png) | ||
--- | --- | --- | --- | --- | | ||
9+ ✔ | ✔ | ✔ | ✔ | 6.1+ ✔ | | ||
## CDN 安装 | ||
@@ -41,2 +44,4 @@ 使用 script 方式安装,VXEAjax 会定义为全局变量 | ||
define(['vue', 'xe-ajax', 'vxe-ajax'], function (Vue, XEAjax, VXEAjax) { | ||
// ES6 环境中不需要启用,使用箭头函数即可 | ||
// 第三个参数如果为true,则启用模拟 Promise 模式,函数内部上下文 this 默认指向当前 vue 实例(和 ES6 箭头函数类似) | ||
Vue.use(VXEAjax, XEAjax, true) | ||
@@ -60,27 +65,6 @@ }) | ||
// 通过vue实例的调用方式 | ||
this.$ajax.getJSON ('/api/user/list', {id: 1}) | ||
this.$ajax.postJSON ('/api/user/save', {id: 1}) | ||
this.$ajax.fetchGet ('/api/user/list', {id: 1}) | ||
this.$ajax.fetchPost ('/api/user/save', {id: 1}) | ||
``` | ||
## 混合函数 | ||
### 文件 ./customs.js | ||
``` shell | ||
export function get1 () { | ||
console.log('自定义的函数') | ||
} | ||
``` | ||
### 示例 ./main.js | ||
``` shell | ||
import Vue from 'vue' | ||
import XEAjax from 'xe-ajax' | ||
import VXEAjax from 'vxe-ajax' | ||
import customs from './customs' | ||
XEAjax.mixin(customs) | ||
Vue.use(VXEAjax, XEAjax) | ||
// 调用自定义扩展函数 | ||
this.$ajax.get1() | ||
``` | ||
## 示例 | ||
@@ -106,6 +90,10 @@ ./Home.vue | ||
init () { | ||
this.$ajax.getJSON('/api/user/list', {id: 123}).then(data => { | ||
this.list = data | ||
}).catch(data => { | ||
this.list = [] | ||
this.$ajax.fetchGet('/api/user/list').then(response => { | ||
if (response.ok) { | ||
response.json().then(data => { | ||
this.list = data | ||
}) | ||
} else { | ||
this.list = [] | ||
} | ||
}) | ||
@@ -112,0 +100,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9095
106