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

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

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


## Required Permissions
Z
zengyawen 已提交
11 12 13

None

Z
zengyawen 已提交
14 15

## Child Components
Z
zengyawen 已提交
16

17
Not supported
Z
zengyawen 已提交
18

Z
zengyawen 已提交
19 20 21 22 23 24

## APIs

QRCode(value: string)

- Parameters
25
  | Name| Type| Mandatory| Default Value| Description|
Z
zengyawen 已提交
26
  | -------- | -------- | -------- | -------- | -------- |
27
  | value | string | Yes| - | Content of the QR code.|
Z
zengyawen 已提交
28 29 30 31


## Attributes

32
| Name| Type| Default Value| Description|
Z
zengyawen 已提交
33
| -------- | -------- | -------- | -------- |
34 35
| color | [ResourceColor](../../ui/ts-types.md) | Black | Color of the QR code.|
| backgroundColor | [ResourceColor](../../ui/ts-types.md) | - | Background color of the QR code.|
Z
zengyawen 已提交
36 37 38


## Events
Z
zengyawen 已提交
39 40 41 42

Among all the universal events, only the click event is supported.


Z
zengyawen 已提交
43 44
## Example

45 46
```ts
// xxx.ets
Z
zengyawen 已提交
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
@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 已提交
64
![en-us_image_0000001256858415](figures/en-us_image_0000001256858415.png)