New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data property with '_' prefixed not rendered properly #2098

Closed
ferry77 opened this Issue Dec 30, 2015 · 13 comments

Comments

Projects
None yet
@ferry77
Copy link

ferry77 commented Dec 30, 2015

Hi,
I am learning Vue and it's been great so far.
When I use underscore '_' in data property name it doesn't render properly, is anyone had the same experience? Am I missing something?
Example in https://jsfiddle.net/7vw8aa36/

Thanks before!

@yyx990803

This comment has been minimized.

Copy link
Member

yyx990803 commented Dec 30, 2015

_ prefixed properties are reserved for Vue's internal properties. They are not available for direct binding (but you can bind to them as $data._message)

@yyx990803 yyx990803 closed this Dec 30, 2015

@ferry77

This comment has been minimized.

Copy link
Author

ferry77 commented Dec 30, 2015

Thanks Evan for your explanation
On 31 Dec 2015 10:04 am, "Evan You" notifications@github.com wrote:

_ prefixed properties are reserved for Vue's internal properties. They
are not available for direct binding (but you can bind to them as
$data._message)


Reply to this email directly or view it on GitHub
#2098 (comment).

@Kaijun

This comment has been minimized.

Copy link

Kaijun commented Oct 31, 2016

@yyx990803

I'm using Vue 2.0. so what's the best naming strategy for a private variable (or a name computed by props)

for example, i have a prop called toggled passed in.
to avoid mutation, i have to define a same variable in data/computed for this prop: return this.toggled

However, the best name i came out with was _toggled... Do you have any advices for naming strategy under such circumstance.

@304NotModified

This comment has been minimized.

Copy link

304NotModified commented Apr 12, 2017

Is this somewhere documented? We noticed that the properties where suddenly undefined.

We were trying to use underscore names for privates (Typescript), so that we we're sure we aren't using privates from the html side.

@posva

This comment has been minimized.

Copy link
Member

posva commented Apr 12, 2017

It is, in the API docs, data

@304NotModified

This comment has been minimized.

Copy link

304NotModified commented Apr 12, 2017

thx. Found it.

For reference:

Properties that start with _ or $ will not be proxied on the Vue instance because they may conflict with Vue’s internal properties and API methods. You will have to access them as vm.$data._property.

https://vuejs.org/v2/api/#data

@narrowtux

This comment has been minimized.

Copy link

narrowtux commented Jun 13, 2017

Sorry if I necro this, I feel like there should be a better explanation in the error message thrown so you know why it's happening. I spent 2 hours today + 30 minutes duck debugging with a colleague to find out why it wasn't taking my data in the view.

@ccodin

This comment has been minimized.

Copy link

ccodin commented Oct 27, 2017

+1 for the necro...
Totally agree, we can understand the reason but the error message is pretty unclear :/

@LinusBorg

This comment has been minimized.

Copy link
Member

LinusBorg commented Oct 27, 2017

Then please open a feature request for a better error message. As you can see from the previous messages in this thread, closed issues are not a good place to continue conversations.

@nats-afs

This comment has been minimized.

Copy link

nats-afs commented Mar 19, 2018

What can be done, when the api rest that you consume returns you properties with '_'?

@sirlancelot

This comment has been minimized.

Copy link
Contributor

sirlancelot commented Mar 19, 2018

What can be done, when the api rest that you consume returns you properties with '_'?

Access it using this.$data._prop

@nats-afs

This comment has been minimized.

Copy link

nats-afs commented Mar 19, 2018

Specifically
I want to reuse a vuex getter in another getter, but the first one has a child object with the name '_embedded' and when I access the spear, I get an error.

@phanan

This comment has been minimized.

Copy link
Member

phanan commented Mar 19, 2018

Guys, what @LinusBorg said above.

@vuejs vuejs locked and limited conversation to collaborators Mar 19, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.