Skip to content

v-if, v-show and subproperty #171

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

Closed
paglias opened this issue Mar 12, 2014 · 5 comments
Closed

v-if, v-show and subproperty #171

paglias opened this issue Mar 12, 2014 · 5 comments

Comments

@paglias
Copy link

paglias commented Mar 12, 2014

Given this code:

<div v-if="selectedItem">
{{selectedItem.text}}
</div>

If item is false, undefined or null the presence of {{selectedItem.text}} transform it into an object with a text property removing its original value.

Is this an intended behavior?

@paglias
Copy link
Author

paglias commented Mar 12, 2014

Also I believe that changing a property from a string to an object won't create getters and setter for the subproperties of the object, right?

@yyx990803
Copy link
Member

This is intended behavior - this is to (1. prevent computed properties from throwing errors 2. enable collecting dependency) when they try to access properties that does not exist yet.

When swapping a string to an object that object will be recursively observed too. (i.e. converted to getter/setters)

I'm in the process of changing v-if to be truly conditional - basically, if the starting value is falsy, things inside simply won't be compiled. That should somehow resolve your problem as well.

@dyu
Copy link

dyu commented Mar 14, 2014

Has the truly conditional v-if landed in dev branch? (didn't see a reference to a commit)

@yyx990803
Copy link
Member

@dyu here: yyx990803/vue@3df6343

@dyu
Copy link

dyu commented Mar 14, 2014

Thanks as always!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants