js-components-basic-web.md 2.2 KB
Newer Older
E
ester.zhou 已提交
1 2
# web
The **\<web>** component displays web page content.
E
ester.zhou 已提交
3 4 5
>**NOTE**
>
>This component is supported since API version 6. Updates will be marked with a superscript to indicate their earliest API version.
E
ester.zhou 已提交
6

E
ester.zhou 已提交
7 8 9
## Required Permissions
ohos.permission.INTERNET, required only for accessing online web pages.

E
ester.zhou 已提交
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
## Constraints
The **\<web>** component does not follow the transition animation. A page allows only one **\<web>** component.

## Child Components
Not supported

## Attributes

| Name| Type| Default Value| Mandatory| Description|
| -------- | -------- | -------- | -------- | -------- |
| src      | string |   -    |   No    |Address of the web page to be displayed. The domain name of the website must compile with the HTTPS protocol and have received an ICP license.|
| id  | string | -  | No |  Unique ID of the component. |


## Styles
Universal style settings are not supported.

## Events
The following events are supported.
E
ester.zhou 已提交
29

E
ester.zhou 已提交
30 31 32 33 34 35 36 37
| Name| Parameter| Description|
| -------- |  -------- | -------- |
| pagestart      | {url: string} | Triggered when web page loading starts.|
| pagefinish  | {url: string} |  Triggered when web page loading is completed. |
| error  | {url: string, errorCode: number, description: string} |  Triggered when an error occurs during web page loading or opening. |

## Methods
The following methods are supported.
E
ester.zhou 已提交
38

E
ester.zhou 已提交
39 40 41 42 43
| Name| Parameter| Description|
| -------- |  -------- | -------- |
| reload      | - | Reloads a page.|

## Example
E
ester.zhou 已提交
44
```html
E
ester.zhou 已提交
45 46 47 48 49 50 51
<!-- xxx.hml -->
<div style="height: 500px; width: 500px; flex-direction: column;">
    <button onclick="reloadWeb">click to reload</button>
    <web src="www.example.com" id="web" onpagestart="pageStart" onpagefinish="pageFinish" on:error="pageError"></web>
</div>
```

E
ester.zhou 已提交
52
```js
E
ester.zhou 已提交
53
// xxx.js
E
ester.zhou 已提交
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
export default {
    reloadWeb() {
        this.$element('web').reload()
    },

    pageStart: function(e) {
        console.info('web pageStart: ' + e.url)
    },

    pageFinish: function(e) {
        console.info('web pageFinish: ' + e.url)
    },

    pageError: function(e) {
        console.info('web pageError url: ' + e.url)
        console.info('web pageError errorCode: ' + e.errorCode)
        console.info('web pageError description: ' + e.description)
    }
}
```