提交 ad65b436 编写于 作者: fxy060608's avatar fxy060608

improve query string logic (undefined || null => '')

上级 002ddba7
import {
hasOwn,
isPlainObject
} from 'uni-shared'
......@@ -35,12 +36,14 @@ function stringifyQuery (url, data) {
query[item[0]] = item[1]
})
for (let key in data) {
if (data.hasOwnProperty(key)) {
if (isPlainObject(data[key])) {
query[encode(key)] = encode(JSON.stringify(data[key]))
} else {
query[encode(key)] = encode(data[key])
if (hasOwn(data, key)) {
let v = data[key]
if (typeof v === 'undefined' || v === null) {
v = ''
} else if (isPlainObject(v)) {
v = JSON.stringify(v)
}
query[encode(key)] = encode(v)
}
}
query = Object.keys(query).map(item => `${item}=${query[item]}`).join('&')
......@@ -98,4 +101,4 @@ export const request = {
params.responseType = Object.values(responseType).indexOf(value) < 0 ? responseType.TEXT : value
}
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册