Skip to content

How about creating subviews with Vue? #146

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
tiye opened this issue Feb 28, 2014 · 4 comments
Closed

How about creating subviews with Vue? #146

tiye opened this issue Feb 28, 2014 · 4 comments

Comments

@tiye
Copy link

tiye commented Feb 28, 2014

It confused me quite long time since I know MVVM, as a developer based on Backbone.
In Backbone, when new views are required, we just do

subView = new ThatView
subView.$el.appendTo parentView

and remove that subView when it disappears:

subView.remove()

So in such a case in the picture below, I would just open View 1 by clicking Button 1,
and click Button A to open Context I..

ui

How do people build such kind of UI in Vue?

@yyx990803
Copy link
Member

If you want, you can totally do something similar in Vue.js:

this.subVue = new SubVue({
    data: this.someDataToInherit
}).$appendTo(this.$el)
// later
this.subVue.$destroy()

This is only necessary when you have super heavy views and you want to explicitly control the lifecycle of the sub view for better memory management. In most cases, you can just compose everything together and use v-if or v-show to display them based on your view state.

@marfalkov
Copy link

@yyx990803 It would be so nice if we could have an option to tell Vue that subVue is a child of this and therefore able to $dispatch messages and catch $broadcast-ed messages in the hierarchy of VMs.

@yyx990803
Copy link
Member

@marfalkov that's a good point. I do have an internal compiler option that does this... it just occurred to me that I should make it a public option: 0893163

So the above example could be:

this.subVue = new SubVue({
    parent: this,
    data: this.someDataToInherit
}).$appendTo(this.$el)
// later
this.subVue.$destroy()

And you'd get all the benefits: access to $parent and its scope, event communication etc..

@marfalkov
Copy link

@yyx990803 Great!

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