Can't access _uid in constrcutor
See original GitHub issueVersion
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:
- Created 5 years ago
- Comments:6 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@NE-SmallTown
Hi.
In the constructer with the
@Component
decorator,this
is not an instance ofVue
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.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 ofdata
function of the argument, you’re able to usethis._uid
.