Closed taha-azzabi closed 5 years ago
Still in the dark here, but this might help: https://stackoverflow.com/questions/43629684/add-cordova-plugins-to-vue-cordova
How to add additional plugins?Could you you give more details?thanks
How to add plugin to the list in src/index.js?
How to add plugin to the list in src/index.js? Have you found the way of doing it? Regards!
@migueldiganchi This plugin has been abandoned https://github.com/kartsims/vue-cordova/issues/28#issuecomment-403891710
If you're willing to avoid this library, as long as your application is properly initialized for Cordova (ie 'deviceready' has fired and cordova.js
is included in the HTML file), you should be able to access registered Cordova plugins from vue components using the cordova.plugins
(window.cordova.plugins) object.
Ex. Access barcode scanner scanner scan method:
cordova.plugins.barcodeScanner.scan((result) => {console.log(result)}, (err) => {console.err(error)});
If accessing through Vue is a hard requirement for some reason, in the root component's mounted lifecycle hook, you could attach Vue.prototype.$pluginName
to cordova.plugins.pluginName
and thereby make it accessible in child components as this.$pluginName
That said if you really want to use this library, look at the source and note:
Create a file which exports an install method & registers on a Vue.cordova
object, ex: https://github.com/kartsims/vue-cordova/blob/master/src/plugins/cordova-plugin-geolocation.js
Add an entry to the array 'pluginsList' in src/index.js
that the filename of the new plugin
@migueldiganchi This plugin has been abandoned #28 (comment)
If you're willing to avoid this library, as long as your application is properly initialized for Cordova (ie 'deviceready' has fired and
cordova.js
is included in the HTML file), you should be able to access registered Cordova plugins from vue components using thecordova.plugins
(window.cordova.plugins) object.Ex. Access barcode scanner scanner scan method:
cordova.plugins.barcodeScanner.scan((result) => {console.log(result)}, (err) => {console.err(error)});
If accessing through Vue is a hard requirement for some reason, in the root component's mounted lifecycle hook, you could attach
Vue.prototype.$pluginName
tocordova.plugins.pluginName
and thereby make it accessible in child components asthis.$pluginName
That said if you really want to use this library, look at the source and note:
- Create a file which exports an install method & registers on a
Vue.cordova
object, ex: https://github.com/kartsims/vue-cordova/blob/master/src/plugins/cordova-plugin-geolocation.js- Add an entry to the array 'pluginsList' in
src/index.js
that the filename of the new plugin
Hello, and thank you for your answer. The problem is that my Vue.cordova.plugins array is empty. I want to install the cordova-sqlite-storage for Vue. After installing it and added as a plugin within Cordova, I'm able to access to vue-cordova. But I cannot get access to the plugin.
@migueldiganchi Got it, I understand
What I'm saying is for your situation, skip this library entirely and use a Cordova plugin directly from your Vue components like this:
cordova.plugins.pluginName.methodName(params)
If the plugin is installed and by the time that Vue component has been mounted, cordova.js
emits a deviceready
event
@valgaze thanks for your comment that is very helpful
It does make sense for people who struggle to include the plugin to just drop the lib completely since it's mostly a helper library
If you'd like to contribute, I'd be happy to have a section in the README with this kind of information. Something along the lines of "You can also access the cordova
object without requiring this library by doing this and that. Support for individual plugins that are not mentioned can also be done by doing this and that.".
I believe people naturally search for a vue and cordova integration when starting such project, and find this repo.
It did make sense for me at the time I created this library, to help onboarding newcomers, but the feedback I am getting is that some get frustrated over the lack of integration to the many plugins out there and unfortunately I can't support them all by myself (testing takes a lot of time).
@kartsims -- Great idea, I'll make a PR tonight
Merged, thank you!
Hi, Could you you give more details to add plugin,please. 1) Clone the repo
2) Create a file named by the plugin in the plugins/ directory 3) Add your plugin to the list in src/index.js 4) Write a tiny doc in docs/_plugins/.md
5) How we re-generate the plugin vue-cordova to use it with our plugin.
thanks