| | |
| | | ## 引用方法 |
| | | |
| | | ```js |
| | | import { |
| | | Fetcher |
| | | } from '@components/bases/Fetcher'; |
| | | import { Fetcher } from '@components/bases/Fetcher'; |
| | | ``` |
| | | |
| | | ## 构造函数 |
| | |
| | | } |
| | | ``` |
| | | |
| | | 注意,为了保证接口数据的扩展性,data 只能接 Object 类型,禁止接其他类型 |
| | | 注意,为了保证接口数据的扩展性,**data 只能接 Object 类型**,禁止接其他类型 |
| | | |
| | | ### 前端统一响应状态码 |
| | | |
| | |
| | | ```js |
| | | import { Fetcher } from '@components/bases/Fetcher'; |
| | | |
| | | class FCommon extends Fetcher {} |
| | | // 请求集 |
| | | class FCommon extends Fetcher { |
| | | |
| | | getUserInfo(user) { |
| | | const url = this.spellURL('getUserInfo', 'User/info'); |
| | | const send = {..user}; |
| | | return this.post(url, send); |
| | | } |
| | | |
| | | } |
| | | |
| | | // 全局单例 |
| | | export const $fetchCommon = new FCommon(); |
| | | ``` |
| | | |
| | | ```js |
| | | import { |
| | | $fetchCommon |
| | | } from '@fetchers/FCommon'; |
| | | import { $fetchCommon } from '@fetchers/FCommon'; |
| | | |
| | | export class PPageName extends Pilot { |
| | | // 数据控制器 |
| | | export class PUserDetail extends Pilot { |
| | | |
| | | // 在数据控制层中,发请求示例 |
| | | onLoadUserInfo() { |
| | | Taro.showLoading(); |
| | | $fetchCommon.getUserInfo(this.userId) |
| | | // 调用请求集发请求示例 |
| | | $fetchCommon.getUserInfo({uid: this.userId}) |
| | | .then(res => { |
| | | Taro.hideLoading(); |
| | | if (!res) { |