分别运行到微信小程序与H5

51 阅读1分钟

在uniapp中使用uni.request请求 使用#ifdef H5和#ifdef MP-WEIXIN分别判断运行到H5端和小程序端


uni.request({
            // #ifdef H5
            url: '/api/接口地址',  //在vue.comfig.js中配置跨域
            // #endif
            // #ifdef MP-WEIXIN
            url: 'http://192.168.1.173/myttp/public/index.php/接口',
            // #endif
            method: "POST",
            data: {
                    //请求参数
            },
            header: {
                    'Content-Type': 'application/x-www-form-urlencoded',
                    'X-Requested-With': 'xmlhttprequest'
            },
            success: (res) => {
                console.log(res)
            }
         })