@bitfirer/http-client
v0.0.1
Published
http request client based on axios
Downloads
68
Readme
@bitfirer/http-client
基于 axios
的 http
请求库
一、安装(Install)
npm install @bitfirer/http-client -S
二、使用(Usage)
1. 实例化
// src/api/index.js
import HttpClient from '@bitfirer/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