0.1.7 • Published 3 years ago

@styleofpicasso/client v0.1.7

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago
1. 安装 与 引入
// 安装 
npm install @styleofpicasso/client --save-dev
或
yarn add @styleofpicasso/client

// 引入
import { Client } from '@styleofpicasso/client';
2. 使用案例
// 使用案例
import { Client } from '@styleofpicasso/client';

export class TestAPI extends Client {
    constructor() {
        super(getway, options: {})
    }
    
    // 获取数据
    getData(param) {
        return this.post('/test/...', param)
    }
}
3. 详细说明
  • 这个服务支持 post/ get / put / delete 这四个方法
// 这里的四个方法都只接受三个参数
url: 请求接口地址
data: 请求参数
options: 请求接口的相应配置信息
  • 以上案例中的getway 是我们请求接口中代理的服务字段
// eg:
proxy : {
    '/api': {
        target: 'http:// ...',
        ....
    }
}
// 服务中的 的继承就是
constructor() {
    super('/api')
}
  • options 配置信息
// 这里的 options 的配置信息包含以下
oprions: {
  // 这些封装里已经默写 
  underscoreRequestData: false,  // 是否将请求参数改成下划线的方式传递给后端
  camelizeResponseData: true, // 是否将后端返回的数据处理成驼峰式
  dataType: 'form' // json || form || multipart (json格式, 正常的form表单格式,上传文件)
  // 这里需要就加
  responseType: 'blob',  // 响应的类型, 上传时可以用到
  timeout: 10000,  // 超时时间
  .....
}