876
876
  • 发布:2020-06-10 15:24
  • 更新:2020-06-10 15:42
  • 阅读:1730

uni.request传递复杂对象

分类:uni-app

js版serialize 实现
function serialize (obj, prefix) {
const str = []
let p
if (obj.length === 0) {
// str.push(encodeURIComponent(prefix) + '=1')
} else {
for (p in obj) {
if (obj.hasOwnProperty(p)) {
const k = prefix ? prefix + '[' + p + ']' : p
let v = obj[p]
if (v instanceof Date) {
v = parseTime(v)
}
str.push((v !== null && typeof v === 'object') ? serialize(v, k) : encodeURIComponent(k) + '=' + encodeURIComponent(
v))
}
}
}

return str.join('&')
}

uni.request.data改造
options.data = serialize(options.data)

0 关注 分享

要回复文章请先登录注册

luch

luch

使用[luch-request](https://www.quanzhan.co/luch-request/)
2020-06-10 15:42