美文网首页
UNIApp 跨域问题解决

UNIApp 跨域问题解决

作者: 秋叶红90 | 来源:发表于2021-07-15 11:51 被阅读0次

    注=== 仅支持本地调试使用,,,正式时候需要后台支持,如果同域名下面默认支持

    准备两个hostUrl

    var hostUrl = "https://xxxxx.com"
    // 本地调试的时候
    var isDebug = true
    if (isDebug) {
        hostUrl = "/DebugApi"
    }
    function getApi(since_id,callBack){
        let url = hostUrl +  '/xx/xx'
        // since_id
        uni.request({
            url:url,
            data:{
                since_id:since_id
            },
            method:"POST",
            success: (res) => {
                console.log(res.data.data)
                callBack(res.data.data)
            }
        })
    }
    
    
    
    

    找到mainfest.json 源码打开粘贴进去即可

    
    "h5" : {
            "title" : "",
            "router" : {
                "mode" : "hash"
            },
            "devServer" : {
                "port" : 8080, 
                "https" : false,
                "disableHostCheck" : true,
                "proxy": {  
                    "/DebugApi": {  
                        "target": "https://xxxxx.com", // 你的目标接口域名
                        "changeOrigin": true,   
                        "secure": true,
                        "pathRewrite" : {
                            "^/DebugApi" : ""
                        }
    
                        
                    } 
                }  
            }
        }
    
    

    相关文章

      网友评论

          本文标题:UNIApp 跨域问题解决

          本文链接:https://www.haomeiwen.com/subject/umvppltx.html