小程序与VUE请求后台接口,传数组

小程序中传递数组的方式如下,request说明官方文档

 1 // 需要对最终传递的数据进行JSON.stringify()
 2 wx.request({
 3     url: 'https://xxxx.com.cn/xxxx', // 后台接口地址
 4     method: 'post',
 5     header: {
 6         'content-type': 'application/json' // 默认值
 7     },
 8     data: JSON.stringify({
 9         id: 100,
10         list: [1, 2, 3, 4],
11         list1: [
12             {
13                 id: 10,
14                 text: '不应该'
15             },
16             {
17                 id: 20,
18                 tetx: '不可能啊'
19             }
20         ]
21     })
22     success: res => {
23         console.log('成功', res)
24     }
25 })

VUE中传递数组,需要使用node,js的Qs(介绍及安装)模块对请求参数进行序列化就可以了,如下:

 1 // common.js公共的api文件
 2 import request from '@/utils/request'
 3 import Qs from 'qs' // 我这里是局部引入,全局引入需要在main.js引入
 4 
 5 // 多文件删除 data:[]
 6 export function filesDelete(data) {
 7   return request({
 8     url: '/api/backstage/upload/deleteMoreFile',
 9     method: 'post',
10     data: Qs.stringify(data, { indices: false }) // 对参数序列化
11   })
12 }