$ui/utils/url

Url操作模块

Source:
Author:
  • 陈华春

Methods

(static) appendQuery(url, query) → {string}

Source:

在url追加参数

Parameters:
Name Type Description
url string

原本的url

query string | object

需要追加的参数,Object|String

Returns:

追加参数后的url

Type
string

(static) getHost(url) → {string}

Source:

获取url的Host段,

Example
let url = 'http://127.0.0.1:8001/api/abc/123'
getHost(url) // -> http://127.0.0.1:8001/
Parameters:
Name Type Description
url string

URL地址

Returns:

Host

Type
string

(static) getParams(regexUrl, url) → {object}

Source:

从url 的 path中提取参数对象,

Example
let regexUrl = '/api/:type/:id' ,
    url = '/api/abc/123'
getParams(regexUrl, url) // -> {type: 'abc', id: 123}
Parameters:
Name Type Description
regexUrl string

url path规则表达式

url string

URL

Returns:

参数键值对

Type
object

(static) parse(str, sepopt, eqopt) → {Object}

Source:

参数字符串转换成对象形式,如:a=1&b=2 转换成 {a:1, b:2}

Parameters:
Name Type Attributes Default Description
str String

需要转换的字符串

sep String <optional>
&

连接符,可选,默认 &

eq String <optional>
=

键值间隔符,可选,默认 =

Returns:
Type
Object

(static) stringify(query) → {string}

Source:

键值对转换成查询字符串

Parameters:
Name Type Description
query object

键值对,对象

Returns:

查询参数字符串

Type
string