From 8a5257531d76276e65e788e9007ce9753f55259c Mon Sep 17 00:00:00 2001 From: jiangkai43 Date: Mon, 26 Dec 2022 03:24:05 +0000 Subject: [PATCH] =?UTF-8?q?update=20zh-cn/application-dev/reference/apis/j?= =?UTF-8?q?s-apis-url.md.=20=E4=BF=AE=E6=94=B9=E5=B1=9E=E6=80=A7=E8=AF=B4?= =?UTF-8?q?=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: jiangkai43 --- .../reference/apis/js-apis-url.md | 244 +++++++++--------- 1 file changed, 122 insertions(+), 122 deletions(-) diff --git a/zh-cn/application-dev/reference/apis/js-apis-url.md b/zh-cn/application-dev/reference/apis/js-apis-url.md index e4fd98d716..f504082b99 100755 --- a/zh-cn/application-dev/reference/apis/js-apis-url.md +++ b/zh-cn/application-dev/reference/apis/js-apis-url.md @@ -366,6 +366,128 @@ params.append('fod', '3'); console.log(params.toString()); ``` +## URL + +### 属性 + +**系统能力:** 以下各项对应的系统能力均为SystemCapability.Utils.Lang + +| 名称 | 类型 | 可读 | 可写 | 说明 | +| -------- | -------- | -------- | -------- | -------- | +| hash | string | 是 | 是 | 获取和设置URL的片段部分。 | +| host | string | 是 | 是 | 获取和设置URL的主机部分。 | +| hostname | string | 是 | 是 | 获取和设置URL的主机名部分,不带端口。 | +| href | string | 是 | 是 | 获取和设置序列化的URL。 | +| origin | string | 是 | 否 | 获取URL源的只读序列化。 | +| password | string | 是 | 是 | 获取和设置URL的密码部分。 | +| pathname | string | 是 | 是 | 获取和设置URL的路径部分。 | +| port | string | 是 | 是 | 获取和设置URL的端口部分。 | +| protocol | string | 是 | 是 | 获取和设置URL的协议部分。 | +| search | string | 是 | 是 | 获取和设置URL的序列化查询部分。 | +| searchParams(deprecated) | [URLSearchParams](#urlsearchparamsdeprecated) | 是 | 否 | 获取URLSearchParams表示URL查询参数的对象。
此属性从API version 7开始支持,从API version 9 开始被废弃。
建议使用params9+替代。| +| params9+ | [URLParams](#constructor9+) | 是 | 否 | 获取URLParams表示URL查询参数的对象。 | +| username | string | 是 | 是 | 获取和设置URL的用户名部分。 | + +### constructor(deprecated) + +> **说明:** +> +> 从API version 7开始支持,从API version 9开始废弃,建议使用[parseURL9+](#parseurl9)替代。 + +constructor(url: string, base?: string | URL) + +URL的构造函数。 + +**系统能力:** SystemCapability.Utils.Lang + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------- | -------- | -------- | +| url | string | 是 | 入参对象。 | +| base | string \| URL | 否 | 入参字符串或者对象。
- string:字符串
- URL:字符串或对象 | + +**示例:** + +```js +let mm = 'https://username:password@host:8080'; +let a = new Url.URL("/", mm); // Output 'https://username:password@host:8080/'; +let b = new Url.URL(mm); // Output 'https://username:password@host:8080/'; +new Url.URL('path/path1', b); // Output 'https://username:password@host:8080/path/path1'; +let c = new Url.URL('/path/path1', b); // Output 'https://username:password@host:8080/path/path1'; +new Url.URL('/path/path1', c); // Output 'https://username:password@host:8080/path/path1'; +new Url.URL('/path/path1', a); // Output 'https://username:password@host:8080/path/path1'; +new Url.URL('/path/path1', "https://www.exampleUrl/fr-FR/toto"); // Output https://www.exampleUrl/path/path1 +new Url.URL('/path/path1', ''); // Raises a TypeError exception as '' is not a valid URL +new Url.URL('/path/path1'); // Raises a TypeError exception as '/path/path1' is not a valid URL +new Url.URL('https://www.example.com', ); // Output https://www.example.com/ +new Url.URL('https://www.example.com', b); // Output https://www.example.com/ +``` + +### parseURL9+ + +static parseURL(url : string, base?: string | URL): URL + +URL静态成员函数。 + +**系统能力:** SystemCapability.Utils.Lang + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------- | -------- | -------- | +| url | string | 是 | 入参对象。 | +| base | string \| URL | 否 | 入参字符串或者对象。
- string:字符串
- URL:字符串或对象 | + +**示例:** + +```js +let mm = 'https://username:password@host:8080'; +Url.URL.parseURL(mm); // Output 'https://username:password@host:8080/'; +``` + +### tostring + +toString(): string + +将解析过后的URL转化为字符串。 + +**系统能力:** SystemCapability.Utils.Lang + +**返回值:** + +| 类型 | 说明 | +| -------- | -------- | +| string | 用于返回网址的字符串序列化。 | + +**示例:** + +```js +const url = new Url.URL('https://username:password@host:8080/directory/file?query=pppppp#qwer=da'); +url.toString(); +``` + + +### toJSON + +toJSON(): string + +将解析过后的URL转化为JSON字符串。 + +**系统能力:** SystemCapability.Utils.Lang + +**返回值:** + +| 类型 | 说明 | +| -------- | -------- | +| string | 用于返回网址的字符串序列化。 | + +**示例:** +```js +const url = new Url.URL('https://username:password@host:8080/directory/file?query=pppppp#qwer=da'); +url.toJSON(); +``` + ## URLSearchParams(deprecated) ### constructor(deprecated) @@ -764,126 +886,4 @@ let params = new Url.URLSearchParams(url.search.slice(1)); params.append('fod', '3'); console.log(params.toString()); ``` - -## URL - -### 属性 - -**系统能力:** 以下各项对应的系统能力均为SystemCapability.Utils.Lang - -| 名称 | 类型 | 可读 | 可写 | 说明 | -| -------- | -------- | -------- | -------- | -------- | -| hash | string | 是 | 是 | 获取和设置URL的片段部分。 | -| host | string | 是 | 是 | 获取和设置URL的主机部分。 | -| hostname | string | 是 | 是 | 获取和设置URL的主机名部分,不带端口。 | -| href | string | 是 | 是 | 获取和设置序列化的URL。 | -| origin | string | 是 | 否 | 获取URL源的只读序列化。 | -| password | string | 是 | 是 | 获取和设置URL的密码部分。 | -| pathname | string | 是 | 是 | 获取和设置URL的路径部分。 | -| port | string | 是 | 是 | 获取和设置URL的端口部分。 | -| protocol | string | 是 | 是 | 获取和设置URL的协议部分。 | -| search | string | 是 | 是 | 获取和设置URL的序列化查询部分。 | -| searchParams | URLSearchParams | 是 | 否 | 获取URLSearchParams表示URL查询参数的对象。 | -| params | URLParams | 是 | 否 | 获取URLParams表示URL查询参数的对象。 | -| username | string | 是 | 是 | 获取和设置URL的用户名部分。 | - -### constructor(deprecated) - -> **说明:** -> -> 从API version 7开始支持,从API version 9开始废弃,建议使用[parseURL9+](#parseurl9)替代。 - -constructor(url: string, base?: string | URL) - -URL的构造函数。 - -**系统能力:** SystemCapability.Utils.Lang - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| url | string | 是 | 入参对象。 | -| base | string \| URL | 否 | 入参字符串或者对象。
- string:字符串
- URL:字符串或对象 | - -**示例:** - -```js -let mm = 'https://username:password@host:8080'; -let a = new Url.URL("/", mm); // Output 'https://username:password@host:8080/'; -let b = new Url.URL(mm); // Output 'https://username:password@host:8080/'; -new Url.URL('path/path1', b); // Output 'https://username:password@host:8080/path/path1'; -let c = new Url.URL('/path/path1', b); // Output 'https://username:password@host:8080/path/path1'; -new Url.URL('/path/path1', c); // Output 'https://username:password@host:8080/path/path1'; -new Url.URL('/path/path1', a); // Output 'https://username:password@host:8080/path/path1'; -new Url.URL('/path/path1', "https://www.exampleUrl/fr-FR/toto"); // Output https://www.exampleUrl/path/path1 -new Url.URL('/path/path1', ''); // Raises a TypeError exception as '' is not a valid URL -new Url.URL('/path/path1'); // Raises a TypeError exception as '/path/path1' is not a valid URL -new Url.URL('https://www.example.com', ); // Output https://www.example.com/ -new Url.URL('https://www.example.com', b); // Output https://www.example.com/ -``` - -### parseURL9+ - -static parseURL(url : string, base?: string | URL): URL - -URL静态成员函数。 - -**系统能力:** SystemCapability.Utils.Lang - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| url | string | 是 | 入参对象。 | -| base | string \| URL | 否 | 入参字符串或者对象。
- string:字符串
- URL:字符串或对象 | - -**示例:** - -```js -let mm = 'https://username:password@host:8080'; -Url.URL.parseURL(mm); // Output 'https://username:password@host:8080/'; -``` - -### tostring - -toString(): string - -将解析过后的URL转化为字符串。 - -**系统能力:** SystemCapability.Utils.Lang - -**返回值:** - -| 类型 | 说明 | -| -------- | -------- | -| string | 用于返回网址的字符串序列化。 | - -**示例:** - -```js -const url = new Url.URL('https://username:password@host:8080/directory/file?query=pppppp#qwer=da'); -url.toString(); -``` - - -### toJSON - -toJSON(): string - -将解析过后的URL转化为JSON字符串。 - -**系统能力:** SystemCapability.Utils.Lang - -**返回值:** - -| 类型 | 说明 | -| -------- | -------- | -| string | 用于返回网址的字符串序列化。 | - -**示例:** -```js -const url = new Url.URL('https://username:password@host:8080/directory/file?query=pppppp#qwer=da'); -url.toJSON(); -``` \ No newline at end of file -- GitLab