ts-basic-components-qrcode.md 1.5 KB
Newer Older
Z
zengyawen 已提交
1
# QRCode
Z
zengyawen 已提交
2

3
The **\<QRCode>** component is used to display a QR code.
Z
zengyawen 已提交
4

E
ester.zhou 已提交
5
> **NOTE**
6
>
E
ester.zhou 已提交
7
> This component is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.
Z
zengyawen 已提交
8

Z
zengyawen 已提交
9 10

## Child Components
Z
zengyawen 已提交
11

12
Not supported
Z
zengyawen 已提交
13

Z
zengyawen 已提交
14 15 16 17 18

## APIs

QRCode(value: string)

E
ester.zhou 已提交
19
**Parameters**
Z
zengyawen 已提交
20

E
ester.zhou 已提交
21 22 23
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| value | string | Yes| Content of the QR code.|
Z
zengyawen 已提交
24 25 26

## Attributes

E
ester.zhou 已提交
27 28 29 30 31 32
In addition to the [universal attributes](ts-universal-attributes-size.md), the following attributes are supported.

| Name| Type| Description|
| -------- | -------- | -------- |
| color | [ResourceColor](ts-types.md#resourcecolor) | Color of the QR code.<br>Default value: **Color.Black**|
| backgroundColor | [ResourceColor](ts-types.md#resourcecolor) | Background color of the QR code.<br>Default value: **Color.White**|
Z
zengyawen 已提交
33 34 35


## Events
Z
zengyawen 已提交
36

E
ester.zhou 已提交
37
Among all the universal events, only the [click event](ts-universal-events-click.md) is supported.
Z
zengyawen 已提交
38 39


Z
zengyawen 已提交
40 41
## Example

42 43
```ts
// xxx.ets
Z
zengyawen 已提交
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
@Entry
@Component
struct QRCodeExample {
  private value: string = 'hello world'

  build() {
    Column({ space: 5 }) {
      Text('normal').fontSize(9).width('90%').fontColor(0xCCCCCC)
      QRCode(this.value).width(200).height(200)

      Text('color').fontSize(9).width('90%').fontColor(0xCCCCCC)
      QRCode(this.value).color(0xF7CE00).width(200).height(200)
    }.width('100%').margin({ top: 5 })
  }
}
```

Z
zengyawen 已提交
61
![en-us_image_0000001256858415](figures/en-us_image_0000001256858415.png)