Skip to content

Accessing computed properties of components mixed into view model from JavaScript #68

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
jcaxmacher opened this issue Feb 4, 2014 · 2 comments
Milestone

Comments

@jcaxmacher
Copy link

Is there a way to access computed properties of components that are "mixed into" a view model from JavaScript? The docs show how to use the v-with directive to access them in HTML, but not from JavaScript.

Here's an example JSFiddle that illustrates the type of composition I'm referring to.

I have a component created with Vue.extend that I am adding to a view model using the components instantiation option. I then want to know the right way to access the computed properties of the component from the view model in JavaScript.

You can access vueInstance.$.component.computedField if the v-component-id directive is used, but this does not work when using v-repeat since the computed field will only refer to the last item in the list.

I may not have the concepts down correctly, but I think there are cases where I would want to get at data from a component in code instead of markup.

@yyx990803
Copy link
Member

Thanks for the question - it is an overlook in design. I will update v-component-id to work with v-repeat so it returns a list of the ViewModels associated with the array, e.g.:

<p v-repeat="items" v-component="item" v-component-id="items">
    ...
</p>
vueInstance.$.items[0].isDisabled

@yyx990803
Copy link
Member

Landed in 2ca2d77 with casper test coverage.
Since I don't checkin built files in dev branches, if you want to try it out you will have to clone the repo and build it yourself. Otherwise this will probably be merged into master in a few days.

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

2 participants