Advertisement
Guest User

Cordova Plugins with Vue + Framework7

a guest
Apr 23rd, 2018
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. Barcode scanner integration
  2.  
  3. **Problem:** can’t access barcode scanner plugin methods from Vue
  4.  
  5. If we can’t figure out how to surmount, may need to abandon Vue altogether & go w/ another approach
  6.  
  7. Reproduce:
  8. 1. Good starter (framework7): https://blog.toast38coza.me/building-a-mobile-app-with-vuejs-cordova-webpack-and-framework-7/
  9. 2. Barcode scanner Cordova plugin (install w/ cordova command): https://www.npmjs.com/package/cordova-plugin-barcodescanner
  10. 3. Attempt to invoke this method:
  11.  
  12. ```js
  13. cordova.plugins.barcodeScanner.scan(
  14. function (result) {
  15. alert("We got a barcode\n" +
  16. "Result: " + result.text + "\n" +
  17. "Format: " + result.format + "\n" +
  18. "Cancelled: " + result.cancelled);
  19. },
  20. function (error) {
  21. alert("Scanning failed: " + error);
  22. }
  23. );
  24. ```
  25.  
  26. ## Issues/Posts:
  27. * https://github.com/AppointmentGuru/webpack-mobile-f7/issues/4
  28. * https://forum.vuejs.org/t/how-to-import-barcodescanner-in-vuejs-component/17608/6
  29. * https://github.com/kartsims/vue-cordova/issues/11
  30. * http://forum.quasar-framework.org/topic/599/cordova-cordova-plugin-qrscanner-plugin-preview-not-showing
  31.  
  32. ## Side-Issue: vue-cordova
  33.  
  34. (Note: There may be a way to sidestep Vue-Cordova altogether)
  35.  
  36. Vue-Cordova: http://kartsims.github.io/vue-cordova/vue-cordova/
  37.  
  38. Vue-cordova exposes a cordova obj (ex Vue.cordova.blahblah) & plugins on global “Vue” but from source it looks like user needs to manually add support plugins (unsuccessful so far):
  39. * https://github.com/kartsims/vue-cordova/issues/11
  40. * https://stackoverflow.com/questions/43629684/add-cordova-plugins-to-vue-cordova
  41. *
  42.  
  43. Idea alluded to by author in closed issue #11 (couldn’t get to work, should be “mounted” of component?)
  44.  
  45. ```js
  46. Vue.cordova.on('deviceready', function () {
  47. cordova.plugins.barcodeScanner...
  48. })
  49. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement