使用vue-resource发送请求代码如下:
Vue.http.post(url,
{
name,
remark
}
).then(function () {
alert('新建成功!');
},function (response) {
alert('新建失败:'+response.body);
})
通过chrome devtools network调试发现 ,post 方式发送时默认将参数转换成json字符串放在请求体中,且请求的content-type=
Content-Type:application/json。在我的服务端使用springmvc参数注入时,无法解析请求。
{
name,
remark
}
办法有二:
1、从浏览器处理,设置
Vue.http.options.emulateJSON = true;
2、从服务端处理,让服务端能接受json,我使用的springmvc,可以使用
@RequestBody 修饰参数对象,接受参数。