官网地址
https://ionicframework.com/docs/native/zbar
安装插件
ionic cordova plugin add cordova-plugin-cszbar
npm install @ionic-native/zbar
app.module.ts中导入
import { ZBar } from '@ionic-native/zbar/ngx';
providers: [
ZBar
],
使用
export class Tab3Page {
constructor(
private zbar: ZBar
) {}
// 二维码或者条形码扫描
doScanning() {
const options: ZBarOptions = {
flash: 'off',
drawSight: true,
text_title: '扫码',
text_instructions: '请把相机对准二维码',
camera: 'back'
};
this.zbar.scan(options)
.then(result => {
alert(result);
})
.catch(error => {
alert(error);
});
}
}