I'm wondering how to deal with dynamic components and events using vue-js 2.3.
Let's say the component home $emit('eventFromHome') and the component archives $emit('eventFromArchives')
What is the way to catch them in the <component></component> ? Does it exist a better/nicer way to do it than the temporary solution?
Dynamic component
var vm = new Vue({
el: '#example',
data: {
currentView: 'home'
},
components: {
home: { /* ... */ },
posts: { /* ... */ },
archive: { /* ... */ }
}
})
<component v-bind:is="currentView"></component>
Static component
var vm = new Vue({
el: '#example',
data: {
currentView: 'home'
},
components: {
home: { /* ... */ },
posts: { /* ... */ },
archive: { /* ... */ }
}
})
<home v-on:eventFromHome=""></home>
<archive v-on:eventFromArchive=""></archive>
Temporary answer
<component
v-bind:is="currentView"
v-on:eventFromHome=""
v-on:eventFromArchive="">
</component>
@eventFromHomeand@eventFromArchivesto the dynamic component.<component v-on:eventFromHome="" v-on:eventFromArchive="" v-bind:is="currentView"></component>? That is what you are saying ?