更新记录

1.0.0(2021-01-22)


平台兼容性

这个封装的请求 是从uViewui 框架里面拆出来的

https://uviewui.com/ 他们的官网

关于比较详细的 API集中管理 请去官网查看

https://uviewui.com/js/apiManage.html

关于比较详细的 Http请求 请去官网查看

https://uviewui.com/js/http.html

common 文件夹下

http.api.js //集中管理请求地址

const test = '/c/c/contetn'

const install = (Vue, vm) => {
    const creatPostApi=(path)=>{
        return (params={})=>vm.$u.http.post(path,params)
    }
    const creatGetApi=(path)=>{
        return (params={})=>vm.$u.http.get(path,params)
    }

    const getTest = creatGetApi(test);

    vm.$u.api = { //暴露出去
        getTest
    }
}

export default {
    install
}

使用方式

 this.$u.api.getTest().then(res=>{
                console.log(res)
             })

http.interceptor.js //拦截器加请求的域名配置


const install=(Vue,vm)=>{
    Vue.prototype.$u.http.setConfig({
        baseUrl: '', //请求域名
        loadingText: '请求中...',
        loadingTime: 10,
        header: {
            'content-type': 'application/json;charset=UTF-8'
        },
        showLoading: true,
        loadingTime: 200
    });
    // 请求拦截,配置Token等参数
    Vue.prototype.$u.http.interceptor.request = (config) => {
        config.header.Token = 'xxxxxx';

        // 方式一,存放在vuex的token,假设使用了uView封装的vuex方式,见:https://uviewui.com/components/globalVariable.html
        // config.header.token = vm.token;

        // 方式二,如果没有使用uView封装的vuex方法,那么需要使用$store.state获取
        // config.header.token = vm.$store.state.token;

        // 方式三,如果token放在了globalData,通过getApp().globalData获取
        // config.header.token = getApp().globalData.username;

        // 方式四,如果token放在了Storage本地存储中,拦截是每次请求都执行的,所以哪怕您重新登录修改了Storage,下一次的请求将会是最新值
        // const token = uni.getStorageSync('token');
        // config.header.token = token;

        return config; 
    }
    //响应拦截x
    Vue.prototype.$u.http.interceptor.response = (res) => {
        // 如果把originalData设置为了true,这里得到将会是服务器返回的所有的原始数据
        // 判断可能变成了res.statueCode,或者res.data.code之类的,请打印查看结果
        if(res.code == 200) {
            // 如果把originalData设置为了true,这里return回什么,this.$u.post的then回调中就会得到什么
            return res.data;  
        } else return false;

    }
}

export default{
    install
}

隐私、权限声明

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

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

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

许可协议

MIT协议

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