Call the scan function.
my.scan
Call the scan function.
Input parameter
Name | Type | Required | Description |
scanType | String | No | Scan code recognition type, the default value is |
hideAlbum | Boolean | No | Whether to hide the album (do not allow selecting pictures from the album, only scanning from the camera), the default value is false. |
success | Function | No | Callback function for successful call |
fail | Function | No | Callback function for failed called |
complete | Function | No | Callback function when the call ends (will be executed whether the call succeeds or fails) |
Return value success
Name | Type | Description |
code | String | Scanned data |
qrCode | String | Return QR code data when scanning QR code |
barCode | String | Return barcode data when scanning barcode |
Error Code
Error Code | Description | Solution |
10 | User canceled | This is a normal user interaction flow branch and does not require special processing. |
11 | Operation failed | The specific cause needs to be checked on the client to assist in troubleshooting. |
Code example
// API-DEMO page/API/scan-code/scan-code.json
{
"defaultTitle": "Scan"
}<!-- API-DEMO page/API/scan-code/scan-code.axml-->
<view class="page">
<view class="page-section">
<form onSubmit="scanCode">
<view>
<button type="primary" onTap="scan">Scan code</button>
</view>
</form>
</view>
</view>// API-DEMO page/API/scan-code/scan-code.js
Page({
scan() {
my.scan({
scanType: ['qrCode','barCode'],
success: (res) => {
my.alert({ title: res.code });
},
});
}
})FAQ
Q: After scanning the mini program experience code, why is the page still loading?
A: It is recommended to check the domain name whitelist configured in the background. The whitelist must be configured if there is a network request on the homepage.