小程序與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 }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM