如何实现在一台电脑上VUE和FLASK的进行本地通信?
FLASK端为
@app.route('/ContractCheckText', methods=['POST'])
@cross_origin()
def ContractCheckText():
text = request.files['text']
print(text)
return '结果'
VUE端为
axios.post('http://127.0.0.1:5000/ContractCheckText', param, {headers: {'Content-Type': 'application/x-www-form-urlencoded'}},) //请求头要为表单
.then(response => {
let resultpath = response.data
console.log(resultpath);
})
FLASK端能接收到,有200提示,但是返回VUE的时候,VUE报错提示为Failed to load http://127.0.0.1:5000/ContractCheckText: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access.
flask 路由的Access-Control-Allow-Origin跨域头视乎没加上,用下面的试试,全局的匹配
from flask_cors import CORS
app = Flask(__name__)
# r'/*' 是通配符,让本服务器所有的 URL 都允许跨域请求
CORS(app, resources=r'/*')
您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!