0

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

3
  • 1
    Do you get any errors reported back you? And if so maybe you could share them with us. Commented Oct 31, 2019 at 4:33
  • Are you trying to listen to event on Vue Component / NativeScript UI element? Commented 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. Commented Oct 31, 2019 at 13:40

1 Answer 1

1

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)
Sign up to request clarification or add additional context in comments.

1 Comment

How do you access the vueComponent.nativeView ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.