I was doing some tests and I noticed that my properties are not valid when I used underscore.
Example:
new Vue({
el : "#form",
data: {
errors: [],
_username: '',
_password: ''
});
on html file:
<input class="uk-input" type="text" v-model="_username" >
<input class="uk-input" type="password" v-model="_password">
With the code above the app won't render. If I remove the underscore it will work, does someone knows why this happens?
As was stated many professional developers have come to use _ (underscore) as a prefix for special cases (Even the developers of Vue found it useful for their purposes!) It is one of two non alpha characters that can be used to start a variable name, $ being the other and is also take by Vue!
User component names should always be multi-word, except for root App components. This prevents conflicts with existing and future HTML elements, since all HTML elements are a single word.
The answer may be found in the documentation
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 asvm.$data._property
In your templates, you will have to reference $data._username
/ $data._password
, eg
<input class="uk-input" type="text" v-model="$data._username" >
<input class="uk-input" type="password" v-model="$data._password">
Demo here ~ https://jsfiddle.net/9bzxuecj/2/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With