今天遇到一个问题,vue前端使用axios 传递给 beego写的后端的时候 死活接收不到数据。折腾了几个小时终于解决了,特此分享一下。

//一开始错误的时候 使用 前端传递参数方式

axios向beego传递数组的坑

后端接收代码

userlist := this.GetStrings("userlist")
//
feelist := this.GetStrings("feelist")

fmt.Println(feelist)
fmt.Println(userlist)

输出打印  []  [] 接收不到 

 

查看GetStrings 方法代码后 发现了端倪

axios向beego传递数组的坑

这个方法接收 一个key 值 然后回把

Reques下的fromdata 对应 传递进来的 key值 取出来

userlist := this.GetStrings("userlist")

如果我们是这样 就是取 key值为  userlist 的东西 在回到上面

axios向beego传递数组的坑这里userlist[x] 多了一个 [x]  所以娶不到。

最后解决办法,前端 将 数组 转 字符串  JSON.stringify

userlist:JSON.stringify(userlist),
feelist:JSON.stringify(feelist),

axios向beego传递数组的坑

后端就可以没收到了,很简单

 

相关文章:

  • 2022-12-23
  • 2021-06-30
  • 2022-12-23
  • 2022-12-23
  • 2021-12-26
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-08-06
  • 2021-07-14
  • 2021-06-11
  • 2021-07-05
  • 2022-12-23
  • 2021-12-12
  • 2022-12-23
相关资源
相似解决方案