更新记录

1.1(2019-09-03)

fix qs stringify

1.0(2019-08-27)

封装 Uniapp 类axios方式的Promise网络请求库

完成get,post,put,delete,upload,intercepter


平台兼容性

封装 Uniapp 类axios方式的Promise网络请求库

完成get,post,put,delete,upload,intercepter

How to use?

import Http from "http";
const http = new Http();
// 配置默认设置
http.config.baseURL = config.baseURL;
//解构方式获取class方法
const { upload, get, post } = http;

// Promise API 请求
export const test = data => get("ajax/echo/text?name=uni-app", data);

// 如果想要全局使用,请在main.js文件中挂载
import * as api from './common/service/api.js'
Vue.prototype.$api = api

// call the method
this.$api.test({ noncestr: Date.now() })
// or
test({ noncestr: Date.now() });

intercepter 拦截器

// 请求拦截器
http.interceptor.request = config => {
  console.log(config)
    // if (config.method === "post") {
    //   config.data = qs.stringify(config.data);
    // }
    // token 放在headers中会变成复杂请求,多一次options请求;body或者query则不会
    // const token = uni.getStorageSync("token");
    // if (token) config.headers["token"] = token;
    return config;
}
// 响应拦截器
http.interceptor.response = response => {
    console.log(response)
    // if (response.config.url.indexOf("users/login") != -1 && response.data.code == 200) {
    //  uni.setStorageSync({
    //      key: "token",
    //      data: response.data.data.token
    //  })
    // }
    return response;
}

隐私、权限声明

1. 本插件需要申请的系统权限列表:

2. 本插件采集的数据、发送的服务器地址、以及数据用途说明:

3. 本插件是否包含广告,如包含需详细说明广告表达方式、展示频率:

许可协议

MIT协议

使用中有什么不明白的地方,就向插件作者提问吧~ 我要提问