10

github地址,喜欢的可以star下哦

1.官方推荐
cors和插件安装解决跨域

2.配置uni-app 中 manifest.json->h5->devServer
manifest.json

    "h5": {
        "devServer": {
            "port": 8000,
            "disableHostCheck": true,
            "proxy": {
                "/dpc": {
                    "target": "http://dpc.dapeis.net",
                    "changeOrigin": true,
                    "secure": false
                }
            }
        }
    }

http请求

uni.request({
    url: '/dpc/getUserInfo', 
    success: (res) => {
        console.log(res.data);
    }
});

这样请求webpack会解析为请求http://dpc.dapeis.net/dpc/

参考资料:

webpack-dev-server
webpack跨域API


potato1314
470 声望8 粉丝