Notice: The Monaca & Onsen UI Community Forum is shutting down.
For Onsen UI bug reports, feature requests and questions, please use the Onsen UI GitHub issues page. For help with Monaca, please contact Monaca Support Team.
Thank you to all our community for your contributions to the forum. We look forward to hearing from you in the new communication channels.
vue-cordova-webpack - use cordova plugins functions
-
Hi,
I’m using
vue-cordova-webpack
(https://github.com/OnsenUI/vue-cordova-webpack).
Does anyone know how to usecordova
plugins from<script></script>
tag in.vue
file, e.g.cordova.InAppBrowser.open
from https://github.com/apache/cordova-plugin-inappbrowseror
window.plugins.socialsharing.share();
from https://github.com/EddyVerbruggen/SocialSharing-PhoneGap-Plugin?
I have found this, but I’m not sure how whether it is the right way when using onsen and vue.js and I don’t know where to find
ons
object.Thanks!
-
@Aden23q Cordova adds its functionality to the
window
object, which is globally available and can be accessed from Vue components as well.ons.ready
is only a way to wait fordeviceready
event to ensure that Cordova is fully loaded, but you can also do the sasme withdocument.addEventListener('deviceready', ...)
. Theons
object is available in Vue components asthis.$ons
, as explained in the docs :+1:
-
great answer, thank you very much.
Regards!
-
Hi @Fran-Diox , I noticed that my code for
cordova
is not working.
I’m using this plugin.I have created a
share()
method that is called when clicking a<v-ons-icon></v-ons-icon>
icon.
Here are some tests I did:share() { this.$ons.ready(function () { window.plugins.socialsharing.share( 'message', 'subject', 'image' ); }); },
share() { document.addEventListener('deviceready', function () { window.plugins.socialsharing.share( 'message', 'subject', 'image' ); }); },
share() { window.plugins.socialsharing.share( 'message', 'subject', 'image' ); },
but no luck.
It does not work on the phone.What am I doing wrong?
Thanks