Rushikesh Shirkar
Rushikesh Shirkar

Reputation: 49

Reference Error : document is not defined in nativescript-vue

var elements = document.getElementsByClassName('active');
while(elements.length > 0){
    elements[0].classList.remove('active');
}
$event.target.classList.add('active');

It shows document not defined error

Upvotes: 1

Views: 1305

Answers (1)

Jen Looper
Jen Looper

Reputation: 428

you're using web technologies in a native mobile application. The best way to get the id of the element is by giving your element a ref and doing something like this:

 const textField = this.$refs.groceryTextField.nativeView

There are lots of good examples in this repo: https://github.com/tralves/groceries-ns-vue/ and you can also checkout the marketplace for more code samples: market.nativescript.org.

Upvotes: 3

Related Questions