• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# QRCode
2
3用于显示单个二维码的组件。
4
5>  **说明:**
6> 该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
7
8
9## 子组件
10
1112
13
14## 接口
15
16QRCode(value: string)
17
18**参数:**
19
20| 参数名 | 参数类型 | 必填 | 参数描述 |
21| -------- | -------- | -------- | -------- |
22| value | string | 是 | 二维码内容字符串。 |
23
24## 属性
25
26除支持[通用属性](ts-universal-attributes-size.md)外,还支持以下属性。
27
28| 名称 | 参数类型 | 描述 |
29| -------- | -------- | -------- |
30| color | [ResourceColor](ts-types.md#resourcecolor) | 设置二维码颜色。<br/>默认值:Color.Black |
31| backgroundColor | [ResourceColor](ts-types.md#resourcecolor) | 设置二维码背景颜色。<br/>默认值:Color.White |
32
33
34## 事件
35
36通用事件仅支持[点击事件](ts-universal-events-click.md)。
37
38
39## 示例
40
41```ts
42// xxx.ets
43@Entry
44@Component
45struct QRCodeExample {
46  private value: string = 'hello world'
47  build() {
48    Column({ space: 5 }) {
49      Text('normal').fontSize(9).width('90%').fontColor(0xCCCCCC).fontSize(30)
50      QRCode(this.value).width(200).height(200)
51
52      // 设置二维码颜色
53      Text('color').fontSize(9).width('90%').fontColor(0xCCCCCC).fontSize(30)
54      QRCode(this.value).color(0xF7CE00).width(200).height(200)
55
56      // 设置二维码背景色
57      Text('backgroundColor').fontSize(9).width('90%').fontColor(0xCCCCCC).fontSize(30)
58      QRCode(this.value).width(200).height(200).backgroundColor(Color.Orange)
59    }.width('100%').margin({ top: 5 })
60  }
61}
62```
63
64![qrcode](figures/qrcode.png)
65