How to get element in nativescript using vue?

Viewed 7530

I want to get Image element with id='item' on created.

I can't seem to find anything on google. Most of the tutorial on the internet is using Typescript and always start with page=args.object

export function pageLoaded(args) {
    page = args.object;
    item = page.getViewById("item");
}
2 Answers

You can use refrences for this.

Sample xml:

<StackLayout ~body class="body" row="1">

or:

<StackLayout ref="body" class="body" row="1">

Sample code:

mounted() {
  let body = this.$refs.body;
}

As mentioned in the comments of the other answers:

<StackLayout ref="body" class="body" row="1">

mounted() {
  let body = this.$refs.body;
}

Also you can access the nativeView by accessing it's property: let nativeLayout = this.$refs.body.nativeView;

In NativeScript-Vue the nativeView of a ViewComponent is the wrapper element of the actual native platform (iOS/Android) element/view.

For example the nativeView of the ref="body" is the StackLayout of the tns-core-modules and it has a nativeViewProtected property which is the actual native framework element (on iOS UIView and android.view.View on Android)

Related