LoginSignup
1
1

More than 3 years have passed since last update.

ionic + vueでqr-scannerを使いたい時のメモ(自分用)

Posted at

https://qiita.com/reon777/items/82f6292248d76d1f3360
ここでvue.jsにcordovaをインストールする

*ここはかなり手こずった。

*cordovaをインストールする場所に要注意

*capacitorでcordovaのプラグインを使う時の方法

$ npm install @ionic-native/qr-scanner
$ npm install cordova-plugin-qrscanner
$ npx cap sync

この時エラー文大量に出てきたけど無視して行った。

これとは微妙に書き方が違うので注意

qrscan.vue

hoge() {
      const qrScanner = new QRScanner(); //新しくインスタンスを生成
// qrScanner.変数名でいろんな機能を使えるようになった
      qrScanner.prepare().then((status) => {
        if (status.authorized) {
          console.log('hogehoge')
          qrScanner.show();
          const scanSub = qrScanner.scan().subscribe((text: string) => {
            console.log(text);
            qrScanner.hide();
            scanSub.unsubscribe();
          });
        }
      }).catch((e) => {
        console.log(e);
      });
    },
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1