本模块提供 URL 查询字符串的操作方法。
- Source:
Methods
(static) append(url, data, optionsopt) → {String}
把键值对集合序列化为查询字符串后拼接到指定URL。
Parameters:
Name | Type | Attributes | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
url |
string | 指定URL。 | |||||||||
data |
Object | string | 键值对集合。 | |||||||||
options |
Object |
<optional> |
参数。
Properties
|
- Source:
Returns:
处理后的URL。
- Type
- String
Example
append('http://abc.com?a=1', { b: 2, c: 3 }); // 'http://abc.com?a=1&b=2&c=3'
append('http://abc.com', { a: 1, b: 2 }); // 'http://abc.com?a=1&b=2'
(static) parse(str) → {Object}
把查询字符串反序列化为键值对集合。
Parameters:
Name | Type | Description |
---|---|---|
str |
string | 查询字符串。 |
- Source:
Returns:
键值对集合。
- Type
- Object
Example
parse('a=1&%E9%94%AE=%E5%80%BC'); // { a: 1, '键': '值' }
parse('a=1&a=2&b=3'); // { a: [1, 2], b: 3 }
(static) stringify(data, optionsopt) → {string}
把键值对集合序列化为查询字符串。
Parameters:
Name | Type | Attributes | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
data |
Object | 键值对集合。 | |||||||||||
options |
Object |
<optional> |
参数。
Properties
|
- Source:
Returns:
序列化结果。
- Type
- string
Example
stringify({ a: 1, '键': '值' }); // 'a=1&%E9%94%AE=%E5%80%BC'
stringify({ a: [1, 2], b: 3 }); // 'a=1&a=2&b=3'