Commit 557233a4 authored by 谢卓城's avatar 谢卓城

1.get 请求参数问题修复.

parent 7a7e7ba6
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
/* eslint-disable no-underscore-dangle */ /* eslint-disable no-underscore-dangle */
import wxRequest from "./wxRequest"; import wxRequest from "./wxRequest";
import defaults from "./defaults"; import defaults from "./defaults";
import { combineUrl, mergeConfig } from "./util"; import { combineUrl, mergeConfig, urlEncode } from "./util";
import Buffer from "../cache/Buffer"; import Buffer from "../cache/Buffer";
import Storage from "../cache/Storage"; import Storage from "../cache/Storage";
import StorageMap from "../cache/StorageMap"; import StorageMap from "../cache/StorageMap";
...@@ -33,10 +33,10 @@ class Axios { ...@@ -33,10 +33,10 @@ class Axios {
return this.request(config); return this.request(config);
} }
get(url, _config = {}) { get(url, data = null,_config = {}) {
const config = { const config = {
..._config, ..._config,
url, url: url + urlEncode(data).substr(1),
method: "GET" method: "GET"
}; };
return this.request(config); return this.request(config);
......
...@@ -65,3 +65,25 @@ export function handleError(res) { ...@@ -65,3 +65,25 @@ export function handleError(res) {
}); });
} }
} }
/**
* param 将要转为URL参数字符串的对象
* key URL参数字符串的前缀
* encode true/false 是否进行URL编码,默认为true
*
* return URL参数字符串
*/
export function urlEncode(param, key, encode) {
if(param==null) return '';
var paramStr = '';
var t = typeof (param);
if (t == 'string' || t == 'number' || t == 'boolean') {
paramStr += '&' + key + '=' + ((encode==null||encode) ? encodeURIComponent(param) : param);
} else {
for (var i in param) {
var k = key == null ? i : key + (param instanceof Array ? '[' + i + ']' : '.' + i);
paramStr += urlEncode(param[i], k, encode);
}
}
return paramStr;
};
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment