这篇文章主要介绍了Vue中get方法和post方法怎么传递数组参数的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇vue中get方法和post方法怎么传递数组参数文章都会有所收获,下面我们一起来看看吧。1、vue
这篇文章主要介绍了Vue中get方法和post方法怎么传递数组参数的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇vue中get方法和post方法怎么传递数组参数文章都会有所收获,下面我们一起来看看吧。
直接放在对象中传递数组
export function getCrApplicationList(data) { var test = [‘111‘, ‘222‘] return request({ url: ‘/applicant/CrApplication/List‘, method: ‘get‘, params: { test } })}
但是这样的话后台是取不到值的,我们需要把数组变成如下这种格式:
test:111
test:222
if (config.method === ‘get‘) { // 如果是get请求,且params是数组类型如arr=[1,2],则转换成arr=1&arr=2 config.paramsSerializer = function(params) { return qs.stringify(params, { arrayFORMat: ‘repeat‘ }) } }
如果get请求中参数是数组格式,则数组里每一项的属性名重复使用。
同样的,post方法传get方法的传参格式时候通用该方法。
封装的接口部分:
export function doFuncTest(idListVal, orderId) { return request({ url: '/xxxx/xxx', method: 'post', baseURL: '//192.168.xxx.xxx:xxxx/xxx/xxx/xxx', params: { idList: idListVal, orderId: orderId } })}
拦截器部分:
if (config.method === 'post') { config.paramsSerializer = function(params) { return qs.stringify(params, { arrayFormat: 'repeat' }) }}
vue的封装接口中,post与get的传参方式是不同的
export function AddAnimalType (params) { return request({ url: baseUrl + '/addAnimalType', method: 'post', data: params })}
调用代码:
下面的 this.formData 是在data中定义的列表里边包含了id等信息
//新增 insertAnimalType () { AddAnimalType(this.formData).then(response => { if (response.status == 0) { succeSSMessage(response.statusText) } else { errMessage(response.statusText) } }).catch(error => { errorCollback(error) }) },
export function selectById (params) { return request({ url: baseUrl + '/selectById', method: 'get', params })}
调用接口:
//获取详情 getDetail () { selectById({ animalId: this.formData.id }).then(response => { if (response.status == 0) { this.formData = response.data.animalType } else { errMessage(response.statusText) } }).catch(error => { errorCollback(error) }) },
这都是pagej.soneasycom的错误:
使用Uview-ui组件时,如果是npm安装 需要在page.JSON中修改easycom配置,
如果是下载安装,则需要有@/ 如果是npm安装 则去掉@/,使用cnpm则无法使用 重新使用npm或者 下载安装
注意:改正后一定重启HBx!!!
关于“vue中get方法和post方法怎么传递数组参数”这篇文章的内容就介绍到这里,感谢各位的阅读!相信大家对“vue中get方法和post方法怎么传递数组参数”知识都有一定的了解,大家如果还想学习更多知识,欢迎关注编程网精选频道。
--结束END--
本文标题: vue中get方法和post方法怎么传递数组参数
本文链接: https://www.lsjlt.com/news/352867.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-05-07
2024-05-07
2024-05-07
2024-05-07
2024-05-07
2024-05-07
2024-05-07
2024-05-07
2024-05-07
2024-05-07
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0