js-components-basic-richtext.md 2.1 KB
Newer Older
E
ester.zhou 已提交
1
# richtext
Z
zengyawen 已提交
2 3


E
ester.zhou 已提交
4 5 6 7 8
>  **NOTE**
>
> - This component is supported since API version 6. Updates will be marked with a superscript to indicate their earliest API version.
>
> - The rich text content must be written in the content area.
Z
zengyawen 已提交
9

E
ester.zhou 已提交
10 11 12
The **\<richtext>** component displays rich text information.

## Required Permissions
Z
zengyawen 已提交
13 14 15

None

E
ester.zhou 已提交
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48

## Attributes

Only the **id**, **style**, and **class** attributes in [Universal Attributes](../arkui-js/js-components-common-attributes.md) are supported.


## Styles

Only the **display** and **visibility** styles in [Universal Styles](../arkui-js/js-components-common-styles.md) are supported.


## Events

In addition to the [universal events](../arkui-js/js-components-common-events.md), the following events are supported.

| Name| Parameter| Description|
| -------- | -------- | -------- |
| start | - | Triggered when loading starts.|
| complete | - | Triggered when the loading starts.|

>  **NOTE**
> - The **focus**, **blur**, and **key** events are not supported.
> 
> - Accessibility events are not supported.
> 
> - When a page containing **\<richtext>** is returned, the page's transition effect does not apply to the area where the rich text is displayed.
> 
> - Make sure the rich text does not go beyond the height of the screen. Otherwise, the excess content will not be displayed.
> 
> - The width cannot be set. By default, the rich text is displayed in full screen.


## Methods
Z
zengyawen 已提交
49 50 51 52

Not supported


E
ester.zhou 已提交
53 54 55
## Example

```html
Z
zengyawen 已提交
56 57 58 59 60 61
<!-- xxx.hml -->
<div style="flex-direction: column;width: 100%;">
  <richtext @start="onLoadStart" @complete="onLoadEnd">{{content}}</richtext>
</div>
```

E
ester.zhou 已提交
62
```js
Z
zengyawen 已提交
63 64 65 66 67 68 69
// xxx.js
export default {
  data: {
    content: `
    <div class="flex-direction: column; background-color: #ffffff; padding: 30px; margin-bottom: 30px;"  style="background-color: #FFFFFF">
      <style>h1{color: yellow;}</style>
      <p class="item-title">h1</p>
E
ester.zhou 已提交
70
      <h1>Text test (h1 test)</h1>
Z
zengyawen 已提交
71
      <p class="item-title">h2</p>
E
ester.zhou 已提交
72
      <h2>Text test (h2 test)</h2>
Z
zengyawen 已提交
73 74 75 76 77 78 79 80 81 82 83
    </div>
    `,
  },
  onLoadStart() {
    console.error("start load rich text:" + JSON.stringify())
  },
  onLoadEnd() {
    console.error("end load rich text:" + JSON.stringify())
  }
}
```