小程序uniapp + uview设置两个baseUrl

1 uview框架
https://www.uviewui.com/components/picker.html
2 在request.js里面拦截器写上

  /**
     * 请求拦截
     * 可使用async await 做异步操作
     */
    uni.$u.http.interceptors.request.use((config) => {
 		// 这一步就是给baseUrl重新赋值 !!!
        if(config.custom.baseUrl){
            config.baseURL = config.custom.baseUrl
        }
        console.log(config,'cofig')
        // 初始化请求拦截器时,会执行此方法,此时data为undefined,赋予默认{}
        config.data = config.data || {}
        // 根据custom参数中配置的是否需要cookie,添加对应的请求头
        if(config?.custom?.cookie) {
             // #ifdef MP-WEIXIN
            config.header.Cookie = uni.getStorageSync("Token");
			// #endif
        }
        // 表单提交
        if (config.custom.form) {
            config.header['content-type'] = "application/x-www-form-urlencoded"
        }
        return config
    }, config => {
        return Promise.reject(config)
    })

3 在api里面设置一个属于模块的record.js文件

export default {
    record: {
        baseUrl:'http://xxx:9938/digitization-oa',
        searchUser: '/xxx/user/selectList',
    },
}

4 在页面中使用

let params = {
        key: value
      };
this.$Http.get(this.$Api.record.searchUser, {
          custom: { baseUrl: this.$Api.record.baseUrl }, params,}) .then((res) => {
          console.log(res)
        })
        .finally(() => (this.loading = false));
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值