@@ -86,8 +86,14 @@ fooApi
86
86
``` js
87
87
// 甚至可以更进一步和 tua-storage 配合使用
88
88
import TuaStorage from ' tua-storage'
89
+ import { getSyncFnMapByApis } from ' tua-api'
89
90
90
- const storage = new TuaStorage ({ ... })
91
+ // 本地写好的各种接口配置
92
+ import * as apis from ' @/apis'
93
+
94
+ const tuaStorage = new TuaStorage ({
95
+ syncFnMap: getSyncFnMapByApis (apis),
96
+ })
91
97
92
98
const fetchParam = {
93
99
key: fooApi .bar .key ,
@@ -103,7 +109,7 @@ const fetchParam = {
103
109
// ...
104
110
}
105
111
106
- storage
112
+ tuaStorage
107
113
.load (fetchParam)
108
114
.then (console .log )
109
115
.catch (console .error )
@@ -155,7 +161,7 @@ export default {
155
161
}
156
162
```
157
163
158
- [ 更多配置请点击这里查看] ( https://tuateam.github.io/tua-api/config/detail .html )
164
+ [ 更多配置请点击这里查看] ( https://tuateam.github.io/tua-api/config/common .html )
159
165
160
166
### 配置导出
161
167
最后来看一下 ` apis/index.js ` 该怎么写:
@@ -180,7 +186,8 @@ tuaApi
180
186
// 链式调用
181
187
.use (... )
182
188
183
- export const somethingApi = tuaApi .getApi (require (' ./something' ).default )
189
+ export const fakeGet = tuaApi .getApi (require (' ./fake-get' ).default )
190
+ export const fakePost = tuaApi .getApi (require (' ./fake-post' ).default )
184
191
```
185
192
186
193
小程序端建议使用 [ @tua-mp/cli ] ( https://tuateam.github.io/tua-mp/tua-mp-cli/ ) 一键生成 api。
@@ -190,15 +197,16 @@ $ tuamp add api <api-name>
190
197
```
191
198
192
199
### 配置的构成
193
- 在 ` tua-api ` 中配置分为三种 :
200
+ 在 ` tua-api ` 中配置分为四种 :
194
201
195
- * 默认配置(调用 ` new TuaApi({ ... }) ` 时传递的)
196
- * 公共配置(和 ` pathList ` 同级的配置)
197
- * 自身配置(` pathList ` 数组中的对象上的配置)
202
+ * [ 默认配置(调用 ` new TuaApi({ ... }) ` 时传递的)] ( https://tuateam.github.io/tua-api/config/default.html )
203
+ * [ 公共配置(和 ` pathList ` 同级的配置)] ( https://tuateam.github.io/tua-api/config/common.html )
204
+ * [ 自身配置(` pathList ` 数组中的对象上的配置)] ( https://tuateam.github.io/tua-api/config/self.html )
205
+ * [ 运行配置(在实际调用接口时传递的配置)] ( https://tuateam.github.io/tua-api/config/runtime.html )
198
206
199
207
其中优先级自然是:
200
208
201
- ` 自身配置 > 公共配置 > 默认配置 `
209
+ ` 默认配置 < 公共配置 < 自身配置 < 运行配置 `
202
210
203
211
<p align =" center " >
204
212
<a href="https://tuateam.github.io/tua-api/config/">👉更多配置点击这里👈</a>
0 commit comments