star-http-client

0.3.1 • Public • Published

star-http-client

基于 axioshttp 请求库

一、安装(Install)

npm install star-http-client -S

二、使用(Usage)

1. 实例化
// src/api/index.js

import HttpClient from 'star-http-client'

class YourApiClient extends HttpClient {
  constructor () {
    super(YourAxiosInstance)
    this.foo = this.foo.bind(this)
    this.bar = this.bar.bind(this)
  }

  foo () {
    return this.get('path/to/api')
  }

  bar (data) {
    return this.post('path/to/api', data)
  }

  static install (Vue) {
    let _this = new YourApiClient()
    HttpClient.install(Vue, '$YourApiClient', _this)
  }
}

export default YourApiClient
2.在父框架配置中传入
// main.js
const conf = {
  ApiClient: YourApiClient // 可以传入一个数组 包含多个 ApiClient 对象 e.g. [ YourApiClient1, YourApiClient2, YourApiClient3 ]
}
3.使用
this.$YourApiClient.foo() // 返回值为一个 Promise

Readme

Keywords

Package Sidebar

Install

npm i star-http-client

Weekly Downloads

1

Version

0.3.1

License

ISC

Unpacked Size

5.36 kB

Total Files

4

Last publish

Collaborators

  • coderzy260