2019/08/13
- 跨域问题
error:Access to XMLHttpRequest at 'http://****' from origin 'http://localhost:8080' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
warning:Cross-Origin Read Blocking (CORB) blocked cross-origin response http://39.97.170.181/fileTranslate with MIME type application/json. See https://www.chromestatus.com/feature/5629709824032768 for more details.
select @ Translate.vue?408e:357
invokeWithErrorHandling @ vue.esm.js?efeb:1863
invoker @ vue.esm.js?efeb:2188
original._wrapper @ vue.esm.js?efeb:7559
解决方法:服务器端设置 ↓
from flask import Response
from flask_cors import CORS
class JSONResponse(Response):
@classmethod
def force_type(cls, response, environ=None):
if isinstance(response, (list, dict)):
response = flask.jsonify(response)
#response.headers['Access-Control-Allow-Credentials'] = 'true'
response.headers['Access-Control-Allow-Origin'] = '*'
#response.headers['Access-Control-Allow-Methods'] = 'OPTIONS,POST'
#response.headers['Access-Control-Allow-Headers'] = 'Content-Type, X-Requested-With'
# return super(Response, cls).force_type(response, environ)
return response
CORS(app)
app.response_class = JSONResponse