|
我第一次在vue中和后台对接接口时使用时,用对象方式传参后台接收的数据始终是为null。
后来在后台给的swagger上测试发现了问题所在: 1.不是所有的传参都可以使用对象方式,要注意swagger上显示的是什么如果是如下代码 "/api/marketComment/showByUser?userId=1&goodsId=23" 这种那就恭喜你只能使用拼接的方式传参了,拼接方式如下 this.$axios.post("/api/marketComment/showByUser?userId="+需要传的参数+"&goodsId="+需要传的参数).then((res)=>{ console.log(res) }).catch((err)=>{console.log("失败")}) & 这个符号很容易忘记写所以要注意 2.还有就是数组和对象的 "/api/marketComment/showByUser" 这种就需要对象或者数组了如下: this.$axios.post("/api/marketComment/showByUser",{需要传的对象}).then((res)=>{ console.log(res) }).catch((err)=>{console.log("失败")}) 建议不要像这样写如下 this.$axios.post( url:{"/api/marketComment/showByUser"},接收的Key:{需要传的对象}).then((res)=>{ console.log(res) }).catch((err)=>{console.log("失败")}) 这样写后台接口无法接收到数据 这是我第一次写vue项目总结出来的,只是我个人看法 可能有错误别喷,我只是个小白 |
|