Cordova Plugins

  1. Add necessary Cordova/PhoneGap plugins to IOS and Android using command line (e.g. Barcode Scanner):
cordova plugin add phonegap-plugin-barcodescanner
  1. Now open folder Application/src/utils/vue-cordova/plugins and add new file called cordova-plugin-barcodeScanner.js and put this content in it:
exports.install = function(Vue, options, cb) {
    document.addEventListener('deviceready',
        () => {
            if (typeof window.cordova.plugins.barcodeScanner === 'undefined') {
                return cb(false);
            }
            // pass through the Barcode Scanner object
            Vue.cordova.barcodeScanner = window.cordova.plugins.barcodeScanner;
            return cb(true);
        },
        false);
};
  1. Add plugin initialization to Application/src/utils/vue-cordova/plugins/index.js:

 














 
 
 
 
 
 
 



import device from './plugins/cordova-plugin-device'
import barcodeScanner from './plugins/cordova-plugin-barcodeScanner'

export default {
    install: (Vue, options) => {

        ...

        device.install(Vue,
            options,
            pluginLoaded => {
                if (pluginLoaded) {
                    Vue.cordova.plugins.push(device);
                }
            });

        barcodeScanner.install(Vue,
            options,
            pluginLoaded => {
                if (pluginLoaded) {
                    Vue.cordova.plugins.push(barcodeScanner);
                }
            });
    }
};
  1. Now you can use plugin in this way:






 







import Vue from 'vue'

...

//Vue Action:
 scanQR(store) {
        Vue.cordova.barcodeScanner.scan(function (result) {
             alert(result.text);
        },
        function (error) {
            alert(error);
        });
    },