uniapp H5 解决跨域

1、请求地址:https://xxxxxx.con/tsetApi/api/getUserInfo

2、修改  manifest.json 

"h5": {"devServer": {
         "port": 8080, //端口号
         "disableHostCheck": true,
         "proxy": {
             "/tsetApi": {
                  "target": "https://xxxxxx.com/", //目标接口域名
                  "changeOrigin": true, //是否跨域
                  "secure": false // 设置支持https协议的代理
                }
            }
     }
}

3、项目中请求

let apiBaseUrl=''
//APP:APP端
/*#ifdef APP-PLUS*/
console.log('APP端')
/*#endif*/
//H5:H5端
/*#ifdef H5*/
apiBaseUrl='/tsetApi'
/*#endif*/

//MP:小程序
/*#ifdef MP*/
apiBaseUrl='https://xxxxxx.con/tsetApi'
/*#endif*/


const config = {
    apiBaseUrl: apiBaseUrl,
}

// 请求地址
url: config.apiBaseUrl + url

 

posted @ 2023-07-17 11:15  (⊙o⊙)买噶  阅读(1042)  评论(0编辑  收藏  举报