question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't access _uid in constrcutor

See original GitHub issue

Version

vue: 2.5.22 vue-class-component: 6.3.2

Reproduction link

https://jsfiddle.net/heaven_xz/uLy6rpwx/

Steps to reproduce

open chrome devtools and see the console

What is expected?

I can access the _uid

What is actually happening?

I can’t access the _uid in the component constructor if I use the decorator of vue-class-component, but without the decorator, I can access the _uid

------------------------- update --------------------------

Seems like I can’t access any fields which has been inited in the Vue constructor if I use decorator(see https://jsfiddle.net/heaven_xz/uLy6rpwx/3/), but I don’t know why I can access $root

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
kaorun343commented, Jan 22, 2019

@NE-SmallTown

Hi.

In the constructer with the @Component decorator, this is not an instance of Vue due to the technical reason, so _uid is not available.

Also, _uid is private, not documented, so maybe it’s better I think to generate a unique id by yourself.

1reaction
kaorun343commented, Jan 22, 2019

The role of @Component is to create a component option from a class. So as to do this, the decorator collect the properties and methods which defined by users. This feature is related to the issue you mentioned.

It’s available to pass a component option to @Component decorator directly , so inside of data function of the argument, you’re able to use this._uid.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't access a property in constructor function - Stack Overflow
I have a constructor function with some properties and prototypes. However, by some reason I can't access the properties in on of the ......
Read more >
Can't access private field in class constructor arguments
This code works in Chrome and Safari, but not Firefox. Actual results: Firefox throws an error: “Uncaught TypeError: can't access private field or...
Read more >
Understanding Class Members (The Java™ Tutorials ...
This ID number is unique to each object and is therefore an instance variable. At the same time, you need a field to...
Read more >
Constructors in Java - GeeksforGeeks
A constructor in Java can not be abstract, final, static, or Synchronized. Access modifiers can be used in constructor declaration to control ...
Read more >
Javanotes 9, Section 5.2 -- Constructors and Object Initialization
... can be used on a constructor definition are the access modifiers public, private, and protected. (In particular, a constructor can't be declared...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found