axios向beego传递数组的坑

今天遇到一个问题,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传递数组的坑

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