7

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 2

9

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

3 Comments

Also you can access the nativeview by accessing it's property: let nativeLayout = this.$refs.body.nativeView;
May I ask, where do you found this? Is it on the official document or vue document?
@GTHell I found this at: github.com/nativescript-vue/nativescript-vue/issues/49 I always try to find a solution for my questions via the nativescript documentation, the vue documentation, the nativescript-vue documentation, the nativescript repository and the nativescript-vue repository. If I can't find anything there I ask the slack community or on Stackoverflow.
6

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)

Comments

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.