Reputation: 151
I have a pretty complex page which is now static. I want to make some parts of the page to be dynamic using Vue. Later I want to make all the page to be an SPA, but this is not an option for now.
The question is - is it possible to make a Vue app that renders its components to different parts of the page without making the whole page to be the Vue's element? Something like this:
new Vue({
store,
router,
render: {
'#header': ReviewsSummaryComponent,
'#score': ScoreComponent,
'#reviews': ReviewsComponent,
'#compliments': ComplimentsComponent
}
})
The most important part here is that I want them to share common store, routes and (not mandatory) parent. Is that possible in Vue?
Upvotes: 0
Views: 53
Reputation: 135802
You can... sort of. You can have multiple Vue instances, which would be connected through the store:
new Vue({
el: "#header",
store,
components: { ReviewsSummaryComponent },
template: "<ReviewsSummaryComponent/>"
});
new Vue({
el: "#score",
store,
components: { ScoreComponent },
template: "<ScoreComponent/>"
});
new Vue({
el: "#reviews",
store,
components: { ReviewsComponent },
template: "<ReviewsComponent/>"
});
new Vue({
el: "#compliments",
store,
components: { ComplimentsComponent },
template: "<ComplimentsComponent/>"
});
As you can see, I have added only the store
. Technically, you can add the router
to them all as well, but that makes little sense, anyway.
Upvotes: 1