提交 ccf4ebdb 编写于 作者: Q qiang

fix: 解决uni.request请求地址拼接不准确的问题

上级 5d8f7c85
...@@ -25,19 +25,19 @@ function setUrl (url, data) { ...@@ -25,19 +25,19 @@ function setUrl (url, data) {
str = str[0].split('?') str = str[0].split('?')
var query = str[1] || '' var query = str[1] || ''
url = str[0] url = str[0]
var search = query.split('&').filter(item => item)
query = {}
search.forEach(item => {
item = item.split('=')
query[item[0]] = item[1]
})
for (var key in data) { for (var key in data) {
if (data.hasOwnProperty(key)) { if (data.hasOwnProperty(key)) {
var keyEncode = encodeURIComponent(key) query[encodeURIComponent(key)] = encodeURIComponent(data[key])
var valEncode = encodeURIComponent(data[key])
var reg = new RegExp('((^|&)' + keyEncode + '=)[^&]*(&|$)', 'i')
if (query.match(reg)) {
query.replace(reg, '$1' + valEncode)
} else {
query += (query.length ? '&' : '') + keyEncode + '=' + valEncode
}
} }
} }
return url + '?' + query + (hash ? '#' + hash : '') query = Object.keys(query).map(item => `${item}=${query[item]}`).join('$')
return url + (query ? '?' + query : '') + (hash ? '#' + hash : '')
} }
/** /**
* 解析响应头 * 解析响应头
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册