问题遇到的现象和发生背景
如何实现在一台电脑上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.