【发布时间】:2020-05-17 18:30:30
【问题描述】:
这是我的烧瓶代码,
@app.route("/", methods=['GET','POST'])
@cross_origin()
def helloWorld():
data = request.json
return jsonify(data)
我在 Vue 中使用 axios 将数据发布到 localhost:5000。我可以发布它,但在烧瓶中它显示为空。
axios.post('http://127.0.0.1:5000/', {
firstName: 'Fred',
lastName: 'Flintstone'
})
.then(function (response) {
console.log(response.data);
})
.catch(function (error) {
console.log(error);
});
当我在 Vue 中这样做时,
axios
.get('http://127.0.0.1:5000')
.then(response => console.log(response))
.catch(error => console.log(error))
我得到正确的输出,即发布的数据,但在烧瓶中我得到 null 作为响应。 有人知道为什么会这样吗?
【问题讨论】:
-
将 CORS 添加到烧瓶中:Flask work with GET, not POST need CORS
-
我已经在 Flask 中添加了 CORS。 @Fazel Farnia 还有什么导致这个问题的原因
标签: api vue.js post flask axios