请求中使用参数用form-data的形式:
var content = new window.FormData();
content.append("id", this.id);
content.append("name", this.name);
this.$http.post("test", content)
.then(function (data) {
if(data.status === 200 && data.ok === true){
this.tipsmessage = '保存成功'
this.success = true
}else{
this.tipsmessage = '保存失败'
this.success = false
}
})
.catch(
function (data) {
console.log('请求出错')
}
)
页面传递参数效果:
为什么传递格式不是这样呢?
根据大家的回答,我做了修改:
this.$http({
url: 'test',
method: 'POST',
data: content,
headers: {
'Content-Type': 'application/x-www-from-urlencoded'
}
})
结果:
content-type已经修改成application/x-www-from-urlencoded这个格式了,但是没有显示传递的参数,为什么呢?
content-type 设置跟在数据后面
key:value格式 可以利用
new URLSearchParams()
方法 然后追加 append元素json格式 那就 声明拼接 对象值太多转换
JSON.stringify()