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!
_
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
)
Thanks Evan for your explanation
On 31 Dec 2015 10:04 am, "Evan You" [email protected] 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
https://github.com/vuejs/vue/issues/2098#issuecomment-168091787.
@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.
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.
It is, in the API docs, data
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.
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.
+1 for the necro...
Totally agree, we can understand the reason but the error message is pretty unclear :/
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.
What can be done, when the api rest that you consume returns you properties with '_'?
What can be done, when the api rest that you consume returns you properties with '_'?
Access it using this.$data._prop
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.
Guys, what @LinusBorg said above.
Most helpful comment
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.