# dream-axios

> axios,http,kackaging

Latest version **1.0.0** (published 2020-11-05) · ISC license · 0 weekly downloads

## Install

```sh
npm install dream-axios
pnpm add dream-axios
yarn add dream-axios
bun add dream-axios
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2020-11-05 |
| First published | 2020-11-05 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 9.8 KB |
| Known vulnerabilities | 0 (+23 in 1 direct dependencies) |
| Install scripts | no |
| Author | LinXuJie |
| Maintainers | linxujie |

## Links

- npm: https://www.npmjs.com/package/dream-axios
- Repository: https://github.com/wedcxy/dream-axios
- Homepage: https://github.com/wedcxy/dream-axios#readme
- Issues: https://github.com/wedcxy/dream-axios/issues
- npm.io page: https://npm.io/package/dream-axios

## Dependencies (1)

- [axios](https://npm.io/package/axios.md) ^0.21.0

## Recent versions

- 1.0.0 (latest) — 2020-11-05

## README

## Dream-http

- 说明

  ```
  dream-http是基于axios进行二次封装，简单化网络请求
  ```

- 快速上手

  ```javascript
  import Vue from 'vue'
  import App from './App.vue'
  import router from './router'
  //1.导入dream-http包
  import DreamHttp from 'dream-axios'
  
  
  Vue.config.productionTip = false
  
  new Vue({
    router,
    render: h => h(App)
  }).$mount('#app')
  
  ```

  

- new DreamHttp类

  参数

  | 参数名称    | 类型   | 说明                 |
  | ----------- | ------ | -------------------- |
  | environment | Object | 配置不同环境下根地址 |
  | overtime    | Number | 配置默认请求超时     |

  environment参数列表

  | 参数名称    | 类型   | 说明               |
  | ----------- | ------ | ------------------ |
  | environment | String | 开发环境的默认路径 |
  | production  | String | 生产环境的默认路径 |
  | test        | String | 测试环境的默认路径 |

  

代码例子：

```javascript
let dreamHttp = new DreamHttp({
    environment:{           //配置不同环境下根地址
     environment:'http://localhost:8999/api/', //开发环境
     production:'http://localhost:8999/api/',  //生产环境
     test:'http://localhost:8999/api/'         //测试
   },
   overtime:1000     //设置请求默认请求超时
})
```

- dreamHttp实例对象方法

| 方法名称   | 参数         | 说明                                                         |
| ---------- | ------------ | ------------------------------------------------------------ |
| requset    | function*2   | 配置请求拦截方法，参数是两个回调函数，1.默认是请求拦截成功的回调data，2.默认是请求拦截失败的回调err |
| response   | function*2   | 配置响应拦截方法，参数是两个回调函数，1.默认是响应拦截成功的回调data，2.默认是响应拦截失败的回调err |
| get        | url , params | 设置get请求                                                  |
| post       | url , params | 设置post请求                                                 |
| setApiPath | Object       | 设置api接口                                                  |
| setToken   | Object       | 设置令牌                                                     |

代码例子：

```javascript
let dreamHttp = new DreamHttp({
    environment:{           //配置不同环境下根地址
     environment:'http://localhost:8999/api/', //开发环境
     production:'http://localhost:8999/api/',  //生产环境
     test:'http://localhost:8999/api/'         //测试
   },
   overtime:1000     //设置请求默认请求超时
})


//requset()配置网络请求拦截
dreamHttp.requset(
function(data){  //data为请求拦截成功的回调参数
    
},
function(err){  //err为请求拦截成功的回调参数
    
})

//response()配置响应拦截
dreamHttp.response(
function(data){  //data为响应拦截成功的回调参数
    
},
function(err){  //err为响应拦截成功的回调参数
    
})

//get()网络请求
let id = 10001
dreamHttp.get('/login?id='+id).then(res=>{
    console.log(res)
})
//或者
dreamHttp.get('/login',{id:id}).then(res=>{
    console.log(res)
})

//post()网络请求
dreamHttp.post('/login',{id:id}).then(res=>{
    console.log(res)
})

//设置请求头令牌，参数是一个对象，对象里面需要tokenName，tokenPrice参数
dreamHttp.setToken({
    tokenName:'token',
    tokenPrice:'shadasgysdfgasfdgsfdgfasgdf'
})

//setApiPath()配置每一个接口路径，然后在get,post请求可以直接调用接口api
dreamHttp.setApiPath({
    login:'/login',
    register:'/register'
})

let api = dreamHttp.api

//打印出来api是
//{
//    login:'/login',
//    register:'/register'
//}

dreamHttp.get(api.login,{id:id}).then(res=>{
    console.log(res)
})
```

报错反应邮箱：3148264655@qq.com

---
_Source: https://npm.io/package/dream-axios · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
