I just started learning Vue and I got some problems with passing events through different components. I'm building a simple todo list app with basic functionalities like adding new tasks and deleting them. This is the link to the repo https://github.com/Polenj86/vue-taskmanager.
The tree structure of my app is:
-root //App.vue
-- childcomponent // NewTask.vue
-- childcomponent // TasksWrapper.vue
-- grandchildcomponent //Task.vue
What I'm trying to achieve is to give a button to Task.vue that let me delete a task from the tasks array in the root. By now I only managed to delete the task by clicking on the entire element with this method:
<app-component @click.native="deleteTask"></app-component>
methods: {
deleteTask(index) {
this.tasks.splice(index, 1)
}
}
What I want is to give this method to the button inside the component and not to the entire component.
This is the grandchildren code:
<template lang="pug">
.panel.panel-default
.panel-body
slot(name="task-content")
.panel-footer
button.btn.btn-sm.btn-primary(@click="deleteTask") Delete task
</template>
How can I inform the root I want to delete this? I tried to use an event emitter but I don't get what should I pass as a second argument in the emitter.
export default {
methods: {
deleteTask() {
this.$emit('taskWasDeleted', ???);
}
}
}
Thanks for help