uni App 常见问题

  1. 开发过程中遇到解决后端服务跨域问题 (简单后端解决)
    豆瓣为例


    image.png
image.png
前端解决:

在根目录 manifest.json 中


image.png

添加

 "h5" : {
       "devServer" : {
           "https" : false,
           "port": 80,
           "disableHostCheck": true,
           "proxy": {
               "/api": {
                   "target": "http://wthrcdn.etouch.cn",
                   "changeOrigin": true,
                   "secure": false,
                   "pathRewrite":{"^/api":""}
               },
          "/douban": {
                   "target": "https://www.douban.com",
                   "changeOrigin": true,
                   "secure": false,
                   "pathRewrite":{"^/douban":""}
               }
           }
       }
   }

调用时


image.png

妈的网上百度半天 没一个是完整解释的哎(可能是太简单吧,但是对我这样的新手来说太致命了弄了半天)
上边说的代理一般在外置浏览器运行时会出现


image.png

在内置浏览器请求时不会出现这个问题
image.png

请求成功(可能是HBuild内置浏览器 做过代理了)


image.png

这样模拟运行也能使用
image.png

打包成功后安装也能使用

你可能感兴趣的:(uni App 常见问题)