0.3.1 • Published 2 years ago
star-http-client v0.3.1
star-http-client
基于 axios 的 http 请求库
一、安装(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 YourApiClient2.在父框架配置中传入
// main.js
const conf = {
ApiClient: YourApiClient // 可以传入一个数组 包含多个 ApiClient 对象 e.g. [ YourApiClient1, YourApiClient2, YourApiClient3 ]
}3.使用
this.$YourApiClient.foo() // 返回值为一个 Promise