在编写vue的post方法时,发现后端一直接收不到。
修改之前:
commitComment1(item,reply) {
console.log(this.inputComment);
this.showItem = false;
let url_data={ //使用qs编译转换 参数 ,将参数赋值与url_data
//qs编译转换的参数, user_id为接口关键字,7为参数值
// 传递测试数据
aid: this.aid,
uid: sessionStorage.getItem("uid") ,
content: this.inputComment,
puid:reply.uid,
parentId:item.cid
};
axios.post('/comment',url_data
).then((res) => {
if (res.data.code === 200)
{
this.$message.success("回复成功!");
this.reload();
}
else
{
this.$message.error("回复失败!");
this.reload();
}
});
},
修改之后:
commitComment1(item,reply) {
console.log(this.inputComment);
this.showItem = false;
let url_data=this.$qs.stringify({ //使用qs编译转换参数 ,将参数赋值与url_data
//qs编译转换的参数, user_id为接口关键字,7为参数值
// 传递测试数据
aid: this.aid,
uid: sessionStorage.getItem("uid") ,
content: this.inputComment,
puid:reply.uid,
parentId:item.cid
});
axios.post('/comment',url_data
).then((res) => {
if (res.data.code === 200)
{
this.$message.success("回复成功!");
this.reload();
}
else
{
this.$message.error("回复失败!");
this.reload();
}
});
},
要点在于要使用qs编译转换参数,使用this.$qs.stringify方法。