1.1.4 • Published 6 years ago

wx-http-axios v1.1.4

Weekly downloads
6
License
MIT
Repository
github
Last release
6 years ago

wx-http-axios 微信原生request封装

修复原生wx-request并发问题 (参考自wepy框架)

安装

npm install wx-http-axios  # npm安装方式
yarn add wx-http-axios  # yarn安装方式

使用指南

// utils/request.js
import http from 'wx-http-axios'
import tips from 'wx-tips'

// 创建实例
const service = http.create({
    baseURL: 'http://your.api.com'
    headers: {
        'content-type': 'application/json'
    },
    data: {
        app_key: 'APP_KEY'
    }
})

// 设置全局请求拦截器
service.interceptors.request.use(config => {
    config.headers['Authorization'] = `Bearer ${getToken()}`
    return config
}, () => {
    tips.loading()
})

// 设置全局响应拦截器
service.interceptors.response.use(config => {
    return config
}, error => {
    return Promise.reject(error)
}, response => {
    console.log(response)
    tips.loaded()
})
export default service
// api/config.js

import service from 'utils/request'

export function getConfig() {
    return service.post('/config', {
        shop_id: 1
    })
}

export function getPages() {
    return service.post('/pages')
}

配置说明

{
    baseURL: '', // 基地址
    headers: {}, // 基础header
    method: 'GET', // 默认请求方法
    data: {} // 基础填充数据
}

方法api

    static create(configure = {}) this
    get(url, data = {}, header = '') Promise
    post(url, data = {}, header = '') Promise
    options(url, data = {}, header = '') Promise
    head(url, data = {}, header = '') Promise
    put(url, data = {}, header = '') Promise
    delete(url, data = {}, header = '') Promise
    trace(url, data = {}, header = '') Promise
    connect(url, data = {}, header = '') Promise
    request(method = '', url, data = {}, header = '') Promise
1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.9

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago