vue-axios-optimize 3.0.0 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -9
- package/package.json +1 -1
- package/utils.js +1 -0
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# vue-axios-optimize使用说明
|
|
2
2
|
|
|
3
3
|
vue-axios-optimize是一个对axios请求优化的vue插件包,引入此包之后,并进行相关配置,即可轻松实现全局请求加载动画,重复请求时取消前面的请求或者阻止后面的请求,并且可实现请求并发数量控制以及接口缓存。
|
|
4
|
-
[可阅读此文章 了解](https://
|
|
4
|
+
[可阅读此文章 了解](https://www.xiaobu.host/vue-axios-optimize)
|
|
5
5
|
|
|
6
6
|
## 安装
|
|
7
7
|
|
|
@@ -56,13 +56,13 @@ module.exports = {
|
|
|
56
56
|
transpileDependencies: [
|
|
57
57
|
"vue-axios-optimize"
|
|
58
58
|
],
|
|
59
|
-
|
|
59
|
+
...
|
|
60
60
|
}
|
|
61
61
|
```
|
|
62
62
|
|
|
63
63
|
## 总结
|
|
64
64
|
|
|
65
|
-
如有疑问,可关注微信公众号【爆米花小布】进行咨询。
|
|
65
|
+
如有疑问,可关注微信公众号【爆米花小布】进行咨询。
|
|
66
66
|
|
|
67
67
|

|
|
68
68
|
|
|
@@ -71,11 +71,11 @@ module.exports = {
|
|
|
71
71
|

|
|
72
72
|
|
|
73
73
|
微信公众号【爆米花小布】,抖音号【爆米花小布】 更多好玩的插件
|
|
74
|
-
[vue2-element-dict字典包插件使用文档](https://www.
|
|
74
|
+
[vue2-element-dict字典包插件使用文档](https://www.xiaobu.host/vue2-element-dict/)
|
|
75
75
|
|
|
76
76
|
[vue2-element-dict字典包插件](https://www.npmjs.com/package/vue2-element-dict)
|
|
77
77
|
|
|
78
|
-
[vue3-element-dict字典包插件使用文档](https://www.
|
|
78
|
+
[vue3-element-dict字典包插件使用文档](https://www.xiaobu.host/vue3-element-dict/)
|
|
79
79
|
|
|
80
80
|
[vue3-element-dict字典包插件](https://www.npmjs.com/package/vue3-element-dict)
|
|
81
81
|
|
|
@@ -85,12 +85,20 @@ module.exports = {
|
|
|
85
85
|
|
|
86
86
|
[vue3-van3-dict移动端字典包插件](https://www.npmjs.com/package/vue3-vant3-dict)
|
|
87
87
|
|
|
88
|
+
[vue3-van4-dict移动端字典包插件](https://www.xiaobu.host/vue3-vant4-dict)
|
|
89
|
+
|
|
88
90
|
[vue3-water-marker水印插件](https://www.npmjs.com/package/vue3-water-marker)
|
|
89
91
|
|
|
90
92
|
[vue2-water-marker水印插件](https://www.npmjs.com/package/vue2-water-marker)
|
|
91
93
|
|
|
92
94
|
## 更新日志
|
|
93
95
|
|
|
96
|
+
### 3.1.0
|
|
97
|
+
|
|
98
|
+
1. 【优化】新增`abortAllRequests`中断所有请求的方法,用于切换路由时调用。
|
|
99
|
+
2. 【优化】新增`utils.js`文件,暴露`createCancelableRequest`,`requestWithRetry`方法,`createCancelableRequest`方法用于实现需要主动中断请求的接口,`requestWithRetry`方法用于实现需要超时重试的接口。
|
|
100
|
+
3. 【提示】`removeCache`这个方法很早就有,这个版本提示下吧 可以用于清除接口缓存的数据。
|
|
101
|
+
|
|
94
102
|
### 3.0.0
|
|
95
103
|
|
|
96
104
|
1. 【优化】无感知续签AccessToken时无需配置多余请求头
|
|
@@ -107,7 +115,7 @@ module.exports = {
|
|
|
107
115
|
|
|
108
116
|
### 2.1.0
|
|
109
117
|
|
|
110
|
-
1. 【优化】新增timeout配置,实现缓存数据时的伪加载时间,从缓存中获取数据时会触发 showLoadingFun, timeout毫秒后会执行hideLoadingFun
|
|
118
|
+
1. 【优化】新增timeout配置,实现缓存数据时的伪加载时间,从缓存中获取数据时会触发 showLoadingFun, timeout毫秒后会执行hideLoadingFun
|
|
111
119
|
|
|
112
120
|
### 2.0.9
|
|
113
121
|
|
|
@@ -135,7 +143,7 @@ module.exports = {
|
|
|
135
143
|
2. 【功能】无感知刷新token的代码逻辑变更
|
|
136
144
|
3. 【修复】配置高并发请求数量后,取消请求存在取消不了的情况
|
|
137
145
|
4. 【优化】配置接口缓存后,新增可删除接口缓存的功能
|
|
138
|
-
5. 【注意】options配置变化,及接口捕获异常处的逻辑判断
|
|
146
|
+
5. 【注意】options配置变化,及接口捕获异常处的逻辑判断
|
|
139
147
|
|
|
140
148
|
### 2.0.1
|
|
141
149
|
|
|
@@ -143,7 +151,7 @@ module.exports = {
|
|
|
143
151
|
注意:如下几种情况不建议配置缓存
|
|
144
152
|
1. 表单提交的接口
|
|
145
153
|
2. 数据频繁更新的接口
|
|
146
|
-
3. 删除数据接口
|
|
154
|
+
3. 删除数据接口
|
|
147
155
|
|
|
148
156
|
### 2.0.0
|
|
149
157
|
|
|
@@ -179,4 +187,4 @@ module.exports = {
|
|
|
179
187
|
|
|
180
188
|
### 1.0.0
|
|
181
189
|
|
|
182
|
-
1. 初始版本
|
|
190
|
+
1. 初始版本
|
package/package.json
CHANGED
package/utils.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import e from"axios";export function createCancelableRequest(t,a,c,n={},s={}){if(a=a.toLowerCase(),!t||"function"!=typeof t[a])throw new Error(`createCancelableRequest:axiosInstance 不存在 ${a} 方法`);const r=e.CancelToken.source(),o={...s,cancelToken:r.token};return{request:()=>{let e;return["get","delete"].includes(a)?e=t[a](c,n):["post","patch","put"].includes(a)&&(e=t[a](c,n,o)),e},cancel:()=>{if(["get","delete"].includes(a)){const e={url:c,method:a,data:n.data||{},params:n.params||{}};t.abortRequestByConfig(e)}else if(["post","patch","put"].includes(a)){const e={url:c,method:a,data:n,config:e};t.abortRequestByConfig(e)}}}}export function requestWithRetry(t,a,c,n={},s={}){let r,o,l=0,i=null,u=!1,m=!1;["get","delete"].includes(a)?m=n?.widthCancel||m:["post","put","patch"].includes(a)&&(m=s?.widthCancel||!1),i=()=>{u=!0,o()};const d=()=>new Promise((i,p)=>{let h=3e3,C=3,R="请求超时,重试中",f={};if(["get","delete"].includes(a)){h=n?.timeout||3e3,C=n?.maxRetryTimes||3,R=n?.retryMessage||"请求超时,重试中",f={...n,timeout:h,maxRetryTimes:C,currentRetryTimes:l,isManualCancel:u,widthCancel:m};const{request:e,cancel:s}=createCancelableRequest(t,a,c,f);r=e,o=s}else if(["post","put","patch"].includes(a)){h=s?.timeout||3e3,C=s?.maxRetryTimes||3,R=s?.retryMessage||"请求超时,重试中",f={...s,timeout:h,maxRetryTimes:C,currentRetryTimes:l,isManualCancel:u,widthCancel:m};const{request:e,cancel:i}=createCancelableRequest(t,a,c,n,f);r=e,o=i}const y=setTimeout(()=>{o(`请求超时(${h}ms),准备重试`),l++,l<=C&&!u?(console.log(`${R},当前重试次数:${l}/${C}`),d().then(e=>i(e)).catch(e=>p(e))):p({name:"RetryExhaustedError",message:`请求超时,已重试${l-1}次,${u?"手动":"自动"}停止重试`,retryTimes:l,config:f})},h);r().then(e=>{clearTimeout(y),i(e)}).catch(t=>{clearTimeout(y),"CanceledError"===t?.name&&u?p(t):"ECONNABORTED"===t?.code||e.isCancel(t)||p(t)})}),p=()=>(l=0,u=!1,d());return m?{request:p,cancel:i}:p()}
|