在作一個公衆號商城,遇到了跨域問題。html
後端用了beego框架json
ctx.ResponseWriter.Header().Set("Access-Control-Allow-Methods", "POST, GET, PUT, OPTIONS") ctx.ResponseWriter.Header().Set("Access-Control-Allow-Origin", "*") ctx.ResponseWriter.Header().Set("Access-Control-Allow-Headers", "Content-Type,Authorization") ctx.ResponseWriter.Header().Set("Access-Control-Max-Age", "1728000") ctx.ResponseWriter.Header().Set("Access-Control-Allow-Credentials", "true") ctx.ResponseWriter.Header().Set("content-type", "application/json")
mainfest設置後端
"h5":{ "devServer": { "port": 9000, "disableHostCheck": true, "proxy" : { "/" : { "target" : "http://localhost:6601/", //端口修改爲你本身的 "changeOrigin" : true, "secure" : false, "pathRewrite" : { "^/" : "/" } } }, "https" : false } },
用了fly請求,因此攔截中千萬不要設置baseURL!!不要設置baseURL!!不要設置baseURL!!跨域