I have multiple Vue Components set up like this:
App.js
|
|-- CreateTasks
|
|-- LatestTasks (displays 20 tasks)
|
|-- FooBar
| |---LatestTasks (displays 10 tasks)
My goal is to trigger an event from the CreateTasks
component when a new task is created, and have all instances of the LatestTasks component update their task list accordingly.
Despite my efforts, I'm having trouble getting this functionality to work properly.
Below is how I've implemented it:
In CreateTasks Component
methods: {
createTask(){
let task = { name: 'newTask' };
this.$emit( 'new-task-created' );
}
}
In LatestTasks Component
methods: {
getLatestTasks(){
// logic to fetch latest tasks
}
}
created() {
window.addEventListener('new-task-created', this.getLatestTasks );
},