I have successfully created two dynamic components. Now, I am looking to trigger the "logThat(someObj)" method of component-two using events: $emit/$on with the arguments being passed as shown in this code snippet:
Vue.component('component-one', {
template: '#template-a',
methods: {
onClick() {
const someObj = {
foo: "foo",
bar: "bar"
}
vm.$emit('selected', someObj)
vm.currentView ='component-two';
}
}
});
//Stuck on this??
/*vm.$on('selected', (someObj) => {
this.logThat(someObj)
})*/
Vue.component('component-two', {
template: '#template-b',
methods: {
onClick() {
vm.currentView ='component-one';
},
logThat(someObj) {
console.log(someObj);
}
}
});
https://jsfiddle.net/wanxe/yuh71e1o/
If you have any insights on how to tackle this situation, your input would be greatly valued :)