I'm developing my first app using NativeScript Vue and I was hoping someone could help me with an issue here: How do you set an event listener to a component programmatically? In a normal vue app you would do: component.$on('eventName', eventHandler), but that is not working. I tried to get the answer searching the matter in google, but with no results. Thank you all
-
1Do you get any errors reported back you? And if so maybe you could share them with us.Tsepo Nkalai– Tsepo Nkalai2019-10-31 04:33:25 +00:00Commented Oct 31, 2019 at 4:33
-
Are you trying to listen to event on Vue Component / NativeScript UI element?Manoj– Manoj2019-10-31 06:34:51 +00:00Commented Oct 31, 2019 at 6:34
-
I was trying to listen to an event on a Vue component using the method '$on', but apparently, that interface is not implemented in nativescript-vue plugin. There was no error thrown, just didn't work. I resolved what I needed by using the nativescript event handler instead of vue's event handler interface.cortezi– cortezi2019-10-31 13:40:10 +00:00Commented Oct 31, 2019 at 13:40
Add a comment
|
1 Answer
I resolved what I needed by using the nativescript event handler instead of vue's event handler interface. https://docs.nativescript.org/core-concepts/events
I was trying to listen to a page event, so my code looks something like this:
const Page = require('tns-core-modules/ui/page').Page
const componentPage = vueComponent.nativeView.page
componentPage.on(Page.navigatedFromEvent, myHandlerMethod)
1 Comment
Austris Cirulnieks
How do you access the
vueComponent.nativeView ?