我正在努力解决这个奇怪的问题,我似乎无法解决.我正在使用isomorphic fetch将数据发布到服务器.我将身体作为JSON字符串发送.但是在服务器上,我无法读取正文,它只是一个空对象.
堆栈是:节点,反应.
这是客户端代码:
handleSubmit = (event) => {
const { dispatch } = this.props;
fetch('/api/me', {
method: 'POST',
header: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
name: 'xxx'
})
})
.then(response => response.json())
.then( json => dispatch( login( json ) ))
.catch( err => console.log(err) )
}
Run Code Online (Sandbox Code Playgroud)
服务器代码:
var jsonParser = bodyParser.json()
app.post( '/api/me', jsonParser, ( req, res ) => {
console.log('req', req.body);
})
Run Code Online (Sandbox Code Playgroud)
我试过谷歌搜索问题.但我发现的少数解决方案并没有达到目的.
非常感谢所有帮助.
BR
马丁
//更新//
想通了,这是一个愚蠢的',我忘记了.'header'应为'header'
我是vue的新手,所以我可能会犯一个菜鸟错误.
我有一个root vue元素 - raptor.js:
const Component = {
el: '#app',
store,
data: {
productList: store.state.productlist
},
beforeCreate: function () {
return store.dispatch('getProductList', 'getTrendingBrands');
},
updated: function (){
console.log(111);
startSlider();
}
};
const vm = new Vue(Component);
Run Code Online (Sandbox Code Playgroud)
使用此模板
<div class="grid-module-single popular-products" id="app">
<div class="row">
<div class="popular-items-slick col-xs-12">
<div v-for="product in productList">
...
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我的商店很简单store/index.js:
import Vue from 'vue';
import Vuex from 'vuex';
import model from '../../utilities/model';
Vue.use(Vuex);
export default new Vuex.Store({
state: {
productlist: []
},
mutations: { …Run Code Online (Sandbox Code Playgroud)