my.scan
Call the scan QR code or bar code function.
Hint: after calling my.scan API, the onHide() and onShow() lifecycle callback function of App and Page will be executed. The following is the executing sequence:
App.onHide() -> Page.onHide() -> App.onShow() -> Page.onShow().
Supported types of mini programs: DSL, H5+
Sample Code
Page({
scan() {
my.scan({
type: 'qr',
success: (res) => {
my.alert({ title: res.code });
},
});
}
})Parameters
Property | Type | Required | Description |
type | String | No | Type for scanning ( by default): : two-dimensional QR scanning frame. : Linear barcode scanning frame. |
hideAlbum | Boolean | No | Hide album entry or not. If it is , there will be an entry for user to select a picture from the album as the scanned picture. Otherwise, user will use camera to scan the content directly. By default, its value is . |
success | Function | No | Callback function upon call success. |
fail | Function | No | Callback function upon call failure. |
complete | Function | No | Callback function upon call completion (to be executed upon either call success or failure). |
Success Callback Function
The incoming parameter is of the Object type with the following attributes:
Property | Type | Description |
code | String | Data returned from scanning. |
qrCode | String | QR code data returned from scanning. |
barCode | String | Bar code data returned from scanning. |
Error Code
Error | Description |
10 | User cancellation. |
11 | Operation failure. |