• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Hyperlink
2
3超链接组件,组件宽高范围内点击实现跳转。
4
5>  **说明:**
6>
7>  - 该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
8>  - 该组件仅支持与系统浏览器配合使用。
9
10## 需要权限
11
12跳转的目标应用使用网络时,需要申请权限ohos.permission.INTERNET。具体申请方式请参考[权限申请声明](../../security/accesstoken-guidelines.md)。
13
14## 子组件
15
16可以包含Image子组件。
17
18
19## 接口
20
21Hyperlink(address: string | Resource, content?: string | Resource)
22
23**参数:**
24
25| 参数名 | 参数类型 | 必填 | 参数描述 |
26| -------- | -------- | -------- | -------- |
27| address | string \| [Resource](ts-types.md#resource) | 是 | Hyperlink组件跳转的网页。 |
28| content | string&nbsp;\|&nbsp;[Resource](ts-types.md#resource) | 否 | Hyperlink组件中超链接显示文本。<br/>**说明:** <br/>组件内有子组件时,不显示超链接文本。 |
29
30## 属性
31
32除支持[通用属性](ts-universal-attributes-size.md)外,还支持以下属性:
33
34| 名称 | 参数类型 | 描述 |
35| -------- | -------- | -------- |
36| color | [ResourceColor](ts-types.md#resourcecolor) | 设置超链接文本的颜色。 |
37
38## 示例
39
40```ts
41@Entry
42@Component
43struct HyperlinkExample {
44  build() {
45    Column() {
46      Column() {
47        Hyperlink('https://example.com/') {
48          Image($r('app.media.bg'))
49            .width(200)
50            .height(100)
51        }
52      }
53
54      Column() {
55        Hyperlink('https://example.com/', 'Go to the developer website') {
56        }
57        .color(Color.Blue)
58      }
59    }.width('100%').height('100%').justifyContent(FlexAlign.Center)
60  }
61}
62```
63
64![hyperlink](figures/hyperlink.PNG)
65