報錯:
Access to XMLHttpRequest at 'https://xxxxxxx.com/api/v1/ios/users' from origin 'http://localhost:8080' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
解決方案:
首先: manifest.json文件中
"h5" : {
"devServer" : {
"disableHostCheck" : true,
"host": "localhost",
"port": "8080",
"proxy" : {
"/api" : {
"target" : "https://xxxxxx.com",
"changeOrigin" : true,
"secure" : true,
"ws" : true,
"pathRewrite" : {
"^/api": ""
}
}
}
}
}
然后:在http請求頭設(shè)置那里 設(shè)置 config.baseURL = '/api' ,